English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Memory allocation nano-benchmark.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-02-15 (20:50)
From: Jon Harrop <jon@j...>
Subject: Re: [Caml-list] Memory allocation nano-benchmark.
On Tuesday 15 February 2005 14:17, Frédéric Gava wrote:
> stupid question, do you use the "-unsafe" option of ocamlopt. It is better
> for arrays...

Having seen a physics student write a C++ program which invalidly read from 
a[n], resulting in him drawing scientific conclusions from physically- 
realistic but non-deterministically- and unquantifiably-erroneous results, I 
strongly advise people to take the extra ~10% performance hit and use array 
bounds checking all the time.

Indeed, I'm in the "remove -unsafe" camp. Even if OCaml only hoisted bounds 
checks in the simplest of cases, I think there would be a strong case for 
removing this option.

> > The code using ordinary arrays runs in 2.8 seconds,
> > using bigarray 0.7 seconds. 4 x 0.7 = 2.8.
> >
> > bigarray is 4 times faster to write than three level
> > ordinary array.

The current array implementation is not great for large array-based 
computations but I'm not sure that this is such a failing because I don't 
think people should be coding large array-based computations in OCaml. Either 
use a dedicated numerical library for handling large matrices/tensors or use 
a more appropriate data structure (typically a tree) to solve "the bigger" 
problem. The asymptotic complexity of such array based computations is rarely 
good and, consequently, real-time performance is often unnecessarily poor.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.