News for hackers. Stuff that matters.
Re:Are functional languages inherently slow? by gleenn on Thursday July 26, 2012 @12:30PM (#4296866)
No, OCaml and Haskell can be faster than C at times. Look at some benchmarks.
Re:Are functional languages inherently slow? by maximilianburke on Thursday July 26, 2012 @12:40PM (#4296930)
Can you point the way to some of these benchmarks?
Re:Are functional languages inherently slow? by wreckimnaked on Thursday July 26, 2012 @01:34PM (#4297398)
for instance: http://shootout.alioth.debian.org/u32/performance.php?test=c...

needless to say that all benchmarks will be very biased, as idiomatic code is not necessarily the most optimized one.

Re:Are functional languages inherently slow? by igouy on Thursday July 26, 2012 @05:43PM (#4298903)
biased: "showing an unreasonable preference or dislike based on personal opinion".

http://dictionary.cambridge.org/dictionary/american-english/...

Can you show that the benchmarks game is as-you-say biased?

Re:Are functional languages inherently slow? by wreckimnaked on Friday July 27, 2012 @07:40PM (#4304063)
You're right, point taken, I clearly misused the word; it has nothing to do with any personal opinion. I was using 'biased' thinking about its meaning on the Machine Learning context [1].

My intention was to state that idiomatic code is not necessarily the most performant one, and that the codes used in the benchmarks game may contain some not very idiomatic optimization codes [2].

That said, it tends to evaluate the implementation of a certain compiler, and not exactly how the constructs and concepts of those languages result on the measured performance.

1: http://en.wikipedia.org/wiki/Inductive_bias 2: http://shootout.alioth.debian.org/u32/benchmark.php?test=cha...

Re:Are functional languages inherently slow? by postfuturist on Thursday July 26, 2012 @03:16PM (#4298015)
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

Re:Are functional languages inherently slow? by mej10 on Friday July 27, 2012 @10:08AM (#4301449)
I 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.

Re:Are functional languages inherently slow? by postfuturist on Friday July 27, 2012 @01:08PM (#4302408)
This 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?
Re:Are functional languages inherently slow? by postfuturist on Friday July 27, 2012 @01:29PM (#4302520)
Why 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.
Re:Are functional languages inherently slow? by mej10 on Friday July 27, 2012 @01:53PM (#4302650)
I 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.

Re:Are functional languages inherently slow? by mej10 on Friday July 27, 2012 @12:32PM (#4302192)
I 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.

Re:Are functional languages inherently slow? by postfuturist on Friday July 27, 2012 @01:06PM (#4302393)
pull request? I'm no Haskell expert (which apparently you need to be to get decent performance.)
Re:Are functional languages inherently slow? by mej10 on Friday July 27, 2012 @01:51PM (#4302631)
My 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

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.

Re:Are functional languages inherently slow? by postfuturist on Friday July 27, 2012 @06:34PM (#4303886)
No 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.

Re:Are functional languages inherently slow? by mej10 on Friday July 27, 2012 @07:43PM (#4304076)
Thats part of the nice thing about the code I sent you - no strictness hints.