Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Hashtbl or ref Map?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Hicks <mwh@d...>
Subject: Re: Hashtbl or ref Map?

> I'd like to have a simple map (association table, not hashed) 
> and share it between OCAML threads. Which module (from efficiency 
> point-of-view) it would better to use for that purpose: Hashtbl 
> or ref Map? 

I was wondering the same thing and did some experiements.  On my pentium 166
with lots of memory, I ran a test which inserted about 150 different strings
into the table and then looked up each string.  The time for the hashtable
operations includes the time to enter and exit a critical section.  I
measured the total time to insert all of the strings, and the total time to
find all of the strings.  The initial size of the hashtable didn't affect
the overall measurements by a significant amount.

Using the bytecode compiler, I found that inserts for the hashtable are
about 4 times faster, and finds are almost twice as fast.  With native code,
the hashtable is about 2.5 times faster for inserts and about 1.3 times
faster for finds.

Of course, the hashtable does not allow different threads to look at
versions of the table created at different times, whereas a map would.

Mike
-- 
Michael Hicks
Ph.D. Candidate, the University of Pennsylvania
http://www.cis.upenn.edu/~mwh            mailto://mwh@dsl.cis.upenn.edu
"I worked with an individual who plugged his power strip back into itself
and for the life of him could not understand why his computer would not
turn on."