[Shootout-list] Stuff

Jon Harrop jon@ffconsultancy.com
Fri, 22 Apr 2005 11:37:00 +0100


On Friday 22 April 2005 04:10, Isaac Gouy wrote:
> > These kinds of things are so difficult to implement in most other
> > languages that programs are either at worst intractable (Fortran)
> > or at best error-prone (C++).
>
> Doesn't that make "these kinds of things" an unlikely choice for any
> vaguely apples-to-apples performance comparison?

If you go down that route, you'll end up with assembler programs written in 
all languages. I don't think anyone wants that.

> Maybe we should have a separate website with programs that are intended
> to be difficult to implement in other languages.

Well, my programs are genuinely useful (solving common problems) so they 
weren't _designed_ to be "difficult to implement in other languages". I did 
select them because they show off the strong points of languages like OCaml 
though, of course. But I'm advocating that they be included in the shootout 
because the shootout currently lacks these kinds of problems.

So if you want to avoid bias then I'd say why is there an nbody program which 
is clearly geared up for Fortran (it even requires Fortran-style 
implementation, IIRC) but there are no other numerical programs which are 
better suited to more advanced languages?

> > 2. Empty program: It sounds silly, but wouldn't the minimal program
> > in each language be an interesting thing for newbies to look at?
>
> Would that look so much different from
> http://shootout.alioth.debian.org/great/benchmark.php?test=hello&lang=all&s
>ort=fullcpu#bench

Yes, that's probably good enough. I'd tweak the C++ version to:

#include <iostream>

int main() {
  std::cout << "hello world" << std::endl;
  return 0;
}

Oh, I had another idea. What about a program to solve x^3 - x - 1 using Newton 
Raphson?

Here's the OCaml code from a post to sci.math.num-analysis I made on this:

let d f x =
  let delta = sqrt epsilon_float in
  (f (x +. delta) -. f (x -. delta)) /. (2. *. delta);;
let rec fixed_point f x1 =
  let x2 = f x1 in if x2 = x1 then x2 else fixed_point f x2;;
let newton_raphson f x = x -. f x /. d f x;;
let f x = x ** 3. -. x -. 1.;;
fixed_point (newton_raphson f) 2.;;

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists