Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Efficiency of 'a list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-05-04 (05:32)
From: Ed L Cashin <ecashin@u...>
Subject: Re: [Caml-list] Efficiency of 'a list writes:

> wrote:
>> Whenever you've got a situation where access is always via
>> straightforward iteration and modification is at the beginning or end
>> of a sequence, it doesn't make sense to use a hash table or even a
>> tree.  When you don't know the size ahead of time, it doesn't make
>> sense to use an array either.  A list is just the right thing in that
>> case.
> I've done a little timing of things, and according to my results:
> If you care about efficiency and use OCaml, you should use lists 
> fairly often, ie if you are always looping and accessing the elements
> in order. OCaml can iterate through a list (recursively) about twice as
> fast as it can iterate through an array.  It can iterate through a 
> list about as fast as or maybe even a little faster than C or C++ can
> iterate through an array. 

Huh.  I wonder why.  I had a couple of guesses, but I don't know my
way around the ocaml sources, so I couldn't follow up on them (without
spending a bit more time than I have  ;).

--Ed L Cashin     PGP public key:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: