3 ms·
But fib is a great benchmark for blog posts. You can write a naive implementation in your least-favorite language, and write a simple iterative implementation
by jrockway 17y ago
But fib is a great benchmark for blog posts. You can write a naive implementation in your least-favorite language, and write a simple iterative implementation in your favorite language, and your favorite language will always win! And that's the most important part of benchmarking, who wins!
Edit: did anyone replying to this post (other than dons) actually read the linked paper?
- dons 17y agoIndeed, no other benchmark is: * so accessible to the naive -- anyone can understand fib! * has so many ways to implement it -- each in different complexity classes! * is so perfect for language pissing contests on the intertubes. Endless fun! A much better idea is to contribute programs to the Great Shootout, http://shootout.alioth.debian.org/u64/benchmark.php?test=all&lang=all http://shootout.alioth.debian.org/u64/benchmark.php?test=all...
- swannodette 17y agofib does present an interesting problem. Any language worth its weight should be able to express the problem in such a way that it can perform 1) quickly, 2) iteratively (tail-recursion) 3) succinctly. Not that many languages can do that.
- jrockway 17y agoTail recursion for two recursive steps per invocation? I don't think so. (Hint: the "naive" implementation of fib that I refer to above is "fib (x + 1) = fib x + fib (x - 1)".)
- swannodette 17y agoWhat are you saying exactly? That fib shouldn't be defined in terms of tail recursion? Of course it doesn't have to be. But it's also the moment that you realize that for loops are entirely unnecessary and broken since they aren't composable the way functions are.
- jrockway 17y agoIteration and tail recursion are orthogonal. Yes, you can implement iteration in terms of function application. But no, the results of benchmarking "fib" won't make your favorite version win.
- igouy 17y agoDoesn't seem that interesting - http://shootout.alioth.debian.org/gp4/benchmark.php?test=recursive&lang=all http://shootout.alioth.debian.org/gp4/benchmark.php?test=rec...
- swannodette 17y agoHeh, no, the most important part about of benchmarking is collecting data so that people can make informed judgements about what language to use on a particular project. Put all those silly benchmarks together and you get a rough sense of how well a language performs. I started learning Lisp specifically because I saw that SBCL could hold it's own against C, C++, Java, Haskell. A dynamic, interactive language that fast? Unbelievable. These days I'd much rather use a language that gives me the full power of the REPL and performs just as well pixel-pushing as it does with web programming.
- swannodette 17y agoRead it. Honestly the paper is mostly a critique of functional programmers resting on their laurels for too long. "Hey guys, our tail-recursive fib is just as fast as a for loop in C" "Yeah that is pretty cool. But uh, we're simulating millions of particles in huge blocks of contiguous memory using C++. Your cons cells are too slow for that." "Optimizing iteration over our list data structure? Uh ... catch you later." Anyways good read and it's great that Haskell continues to take performance very seriously without abandoning expressive capability.
- dons 17y agoI can't tell from your post, but remember: this paper is from 1993. That we still today have Ruby vs Lisp posts with fib(n) as the test is pathetic. And as a Haskell guy, I'm going to call out anyone trying to use fibonacci to measure things, even though GHC is kicking butt.
- Patient0 17y agoDon't forget that there's also an O(1) closed form solution (and in fact you can derive a closed form solution for any linear recurrence relation: http://en.wikipedia.org/wiki/Recurrence_relation http://en.wikipedia.org/wiki/Recurrence_relation). This is more useful though for things like calculating the size of a mortgage balance after N repayments.