Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] bigarrays and toplevel on Win32?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Bruce Hoult <bruce@h...>
Subject: Re: [Caml-list] bigarrays and toplevel on Win32?
>The party line on unsafe array accesses is unclear: on the one hand,
>we do not want to encourage their use, as it can break type safety and
>dramatically reduce the safety of the programs; on the other hand,
>they are handy when benchmarking against C or Fortran :-)

We've got a benchmark over at Gwydion Dylan that does a simpleminded 
Sieve of Eratosthenes

   <http://www.ccc.de/cgi-bin/cvsweb/gd/examples/sieve-mark/>

While our Dylan code is currently a bit slower than C (about 11%), 
the presence or absence of array bounds checking makes almost no 
difference at all on modern superscalar CPUs such as the P6 (P-Pro, 
PII, PIII) or PowerPC G3/G4.

   Five Hundred Thousand Integer Sieve
   ===================================

   Implementation           Seconds
   --------------           -------
   C                           0.33
   Dylan w/o bounds checks     0.37
   Dylan w/ bounds checks      0.38
   Python w/ 'for' loops      11.40
   Python w/ 'while' loops    15.03
   Perl 5                     24.58


   Five Million Integer Sieve of Eratosthenes
   ==========================================

   Implementation           Seconds
   --------------           -------
   C                           3.90
   Dylan w/o bounds checks     4.33
   Dylan w/ bounds checks      4.35
   Python w/ 'for' loops     FAILED (massive swapping)
   Python w/ 'while' loops   156.83
   Perl 5                    FAILED (bad vector representation?)

-- Bruce

-------------------------------------------------------

The Dylan code is below. The other language implementation can be 
found in the CVS (via the web as above, or from 
:pserver:anoncvs@berlin.ccc.de:/home/cvsroot

define constant $fixed-bound = 500000;

define constant <int-vector> =
   limited(<simple-vector>, of: <integer>, size: $fixed-bound);

define function main()
   let vec :: <int-vector> = make(<int-vector>, fill: 0);

   for (i from 0 below vec.size)
     vec[i] := i + 1;
   end for;

   vec[0] := 0;
   let prime-count = 0;

   for (i from 1 below vec.size)
     if (vec[i] ~= 0)
       prime-count := prime-count + 1;
       let prime = i + 1;
       for (j from (i + prime) below vec.size by prime)
         vec[j] := 0;
       end for;
     end if;
   end for;

   format("There are %d primes less than or equal to %d.\n",
          prime-count, $fixed-bound);
end function main;

main();
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr