7 ms·
I did a benchmark. Naive Haskell implementation took 28 seconds, heavily optimized / hinted Haskell version took 11 seconds. Naive C implementation took 0.3 sec
by postfuturist 14y ago
I did a benchmark. Naive Haskell implementation took 28 seconds, heavily optimized / hinted Haskell version took 11 seconds. Naive C implementation took 0.3 seconds.
https://github.com/deliciousrobots/sml_life https://github.com/deliciousrobots/sml_life
- mej10 14y agoI replaced the array/"surrounding" list with an unboxed vector, and removed the strictness annotations and it runs at ~0.85 on my machine, while the C code runs at around ~0.5. The code is so incredibly close to your SML code (where you also spell out that you are using the Vector type). I am just blown away by how matter of fact you were in your statement. Please either change your benchmark to use the same data type as all of the other examples, or stop using it as an example of Haskell's performance.
- postfuturist 14y agopull request? I'm no Haskell expert (which apparently you need to be to get decent performance.)
- mej10 14y agoMy point is, I am not Haskell expert, but I know that linked lists aren't an efficient data structure for what we're doing. You didn't use lists in your other implementations, so it was just weird that you did for Haskell (originally, and then sort of again for life-array.hs). For your life-array.hs implementation, you replaced the Grid with an array, but not the "surroundings" with one, even though you used Vector for both in your SML implementation. Built with -O2 option: https://gist.github.com/3189306 https://gist.github.com/3189306 Sorry if I came off a bit assholish. People have been saying that you need to be a Haskell expert to get good performance forever, and in my experience this just isn't true. I will admit that there is clearly a problem with how things are introduced, as it is common that new Haskellers think they can use lists for every thing. I am sure part of the problem is that this is one of the few data structures available from the Prelude.
- postfuturist 14y agoNo sweat, thanks for the gist, I'll add it the repo. I'm impressed, actually, if it brings the runtime under a second, because only a couple languages managed that. The act of finding the correct strictness hints seems a bit like black magic.
- mej10 14y agoThats part of the nice thing about the code I sent you - no strictness hints.
- mej10 14y agoI have no idea what is heavily optimized about that Haskell code. I am no Haskell expert, but all you did was use an unboxed array. I added one strictness annotation to the "v" parameter on your iter function and it reduced the time from 10 seconds to 1.5 on my laptop. None of the other code you wrote uses a linked list, so I don't know why you used them for Haskell. You used vector types for most of them (which Haskell has, by the way). Pretty disingenuous. I admit that the prominent use of lists in newbie Haskell tutorials could have mislead you, but you seem to know the difference in data types since you used vectors everywhere else.
- postfuturist 14y agoThis is my first Haskell code, so I read several sources, and posted my code to some online sources asking for help. That's what I came up with. I tried a bunch of strictness hints, I found one that cut the time in half. Lots of trial and error. Apparently, there's another one I didn't find. Could you submit a pull request?
- postfuturist 14y agoWhy did you accuse me of being disingenuous? I used an Array (life-array.hs), if Haskell implements Arrays as a linked list... well, that's a problem.
- mej10 14y agoI accused you of that, because it seemed like you knew what you were doing with the other implementations, and then just suddenly forgot data structure performance when you got to Haskell. It was an asshole move, and I am sorry. They aren't linked lists, but you still used a linked list internal to your "iter" function, where you used a vector (or array) there in other implementations.