Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Benchmark] NBody
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Hars <hars@b...>
Subject: Re: [Caml-list] [Benchmark] NBody
Xavier Leroy wrote:
> Ah, another micro-benchmark.  Great pasttime!  

I tried it on an Athlon64, with ocaml 3.08.1 and gcc 3.3.4, and the ocaml 
version is consistently within a factor of 1.5 of the C version (which is 
faster than the C version with -ffast-math). (See blow for data.)

> The x86 floating-point stack is an awfully bad match for the
> register-based OCaml code generation model

Bu given that the ocaml code generator is register based, I am a bit surprised 
that it uses only a bit more a third of the FP registers on an Athlon64:

$ gcc  -O3 -S nbody.c
$ perl -ne 'while (/(xmm\d+)/g) {print "$1\n"}' nbody.s | sort -u | wc -l
16
$ ocamlopt -o nbody_ml40 -inline 40 -unsafe -S nbody.ml
$ perl -ne 'while (/(xmm\d+)/g) {print "$1\n"}' nbody.s | sort -u | wc -l
6

Yours, Florian.

----- Cutting here may damage your screen -----

ocamlopt -o nbody_ml10 -inline 10 -unsafe nbody.ml
ocamlopt -o nbody_ml40 -inline 40 -unsafe nbody.ml
ocamlopt -o nbody_ml40s -inline 40 nbody.ml
gcc  -O3 -o nbody_c nbody.c -lm
gcc -ffast-math  -O3 -o nbody_cf nbody.c -lm

    n       ml10    ml40    ml40s   c        cf
     1000    0.00    0.00    0.00    0.00    0.00
    10000    0.01    0.01    0.01    0.01    0.01
   100000    0.15    0.12    0.14    0.10    0.11
   200000    0.19    0.10    0.11    0.08    0.09
   500000    0.31    0.25    0.28    0.21    0.22
  1000000    0.60    0.50    0.56    0.43    0.45
  2000000    1.22    1.00    1.12    0.87    0.90
  3000000    1.83    1.50    1.68    1.30    1.35
  4000000    2.35    2.00    2.24    1.71    1.80