News for hackers. Stuff that matters.
Re:Tom, Dick & Harry by atto on Wednesday February 06, 2013 @08:57PM (#5180058)
Interestingly, Dick's code is by far the fastest using those implementations. For a sample size of 1,000,000 employees (to highlight the efficiency difference):

Tom (sorted version): 1510ms

Dick (min-linear version): 113ms

Harry (monoid version): 995ms

Re:Tom, Dick & Harry by graue on Wednesday February 06, 2013 @11:22PM (#5180508)
If it's fair for you to benchmark this, it's surely also fair for me to point out that in a lazily-evaluated language (Haskell!), Tom's approach is O(n) and equivalent to Dick's. :)
Re:Tom, Dick & Harry by fusiongyro on Wednesday February 06, 2013 @11:39PM (#5180560)
That's true if you pick the right sort algorithm. I'm not sure if it is true of whatever happens to be in Data.List; I wouldn't be surprised either way.
Re:Tom, Dick & Harry by jes5199 on Wednesday February 06, 2013 @10:33PM (#5180359)
I find that to be pretty typical - naive solutions are bad for Big-O reasons. If you solve the math on paper and implement a straightforward algorithm, you get the fastest possible solution. If you push some of that math into the type system of your language, you get something that should be Big-O equivalent to the fastest possible solution, but the machinery of the type system never gets fully optimized away. There might be other advantages, though, of having that machinery - your compiler might be able to detect errors in your code, or you might be able to use higher-level constructs to make more concise code. Maybe.
Re:Tom, Dick & Harry by davidroberts on Wednesday February 06, 2013 @10:48PM (#5180410)
So the ultimate point is the futility of spending any time optimizing a solution to a problem that at most requires 2 seconds to run.
Re:Tom, Dick & Harry by greendestiny on Wednesday February 06, 2013 @09:40PM (#5180169)
I don't think the point is the implementation itself, just what the author finds interesting in a problem. After all the 'plus' operator just does a series of ordered comparisons like the minBy solution does.
Re:Tom, Dick & Harry by atto on Wednesday February 06, 2013 @09:57PM (#5180231)
Sure. However, it does represent problems I've seen before with "overly" (subject to the person, I guess) complex solutions that end up being significantly less efficient. In this case, the problem is actually the `.toSet`, which forces a second iteration of the dataset. If the Monoid class was rewritten (yes, to be less mathematically pure) to use Seqs, it's nearly identical performance (as expected) as the linear solution.

Fun performance graph: http://i.imgur.com/2rOvb6V.png

Re:Tom, Dick & Harry by greendestiny on Wednesday February 06, 2013 @10:34PM (#5180366)
That is interesting. Personally I didn't find framing the original problem as monoid enlightening at all, but that's what I thought the author was getting at.