caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Christoph Bauer <christoph.bauer@lms-gmbh.de>
Cc: Damien Doligez <damien.doligez@inria.fr>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] generic Hashtbl.to_array
Date: Wed, 26 Jul 2006 02:19:49 +1000	[thread overview]
Message-ID: <1153844390.1389.53.camel@rosella.wigram> (raw)
In-Reply-To: <26EB47FDD566A7469FC862DAF373792F017112A1@kaiserslautern1.lmsintl.com>

On Tue, 2006-07-25 at 14:00 +0200, Christoph Bauer wrote:
> Hi,
> 
> > let to_array t =
> >    let init = ref None in
> >    begin try Hashtbl.iter (fun k v -> init := Some (k,v); 
> > raise Exit) t
> >    with Exit -> ()
> >    end;
> >    match !init with
> >    | None -> [| |]
> >    | Some i ->
> >      let a = Array.make (Hashtbl.length t) i in
> >      ignore (Hashtbl.fold (fun k v i -> a.(i) <- (k, v); i + 1) t 0);
> >      a
> > ;;
> 
> it's curious, but this solution is slower than the others!
> 
> [skaller's solution seems to be the same, so I
> include only this one in the "benchmark"]

This is not entirely surprising, since Ocaml wastes time 
first initialising the array.. and then assigning the same 
cells new values, recycling the same store through the 
cache twice. However there is no need for a secondary
data structure, which may delay hitting limits of the
next level of caching (for example VM paging disk).

I see in your tests the number of elements is 100,000.
It would be interesting to increase this in a series
of tests to see if the performance tradeoffs change:
cache effects would predict a 'kink' when you hit
cache boundaries?

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2006-07-25 16:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-25 12:00 Christoph Bauer
2006-07-25 16:19 ` skaller [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-07-26 14:41 AW: " Christoph Bauer
2006-07-26 14:53 ` Tom
2006-07-26  2:16 oleg
2006-07-26  9:48 ` [Caml-list] " Damien Doligez
2006-07-25 15:53 AW: AW: " Christoph Bauer
2006-07-25 16:35 ` Tom
2006-08-15  8:26   ` Stéphane Glondu
2006-07-25 12:44 AW: " Christoph Bauer
2006-07-25 15:20 ` Tom
2006-08-15  8:08   ` Stéphane Glondu
2006-07-25  8:29 Christoph Bauer
2006-07-25  9:14 ` [Caml-list] " Erick Tryzelaar
2006-07-25 11:45 ` Damien Doligez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1153844390.1389.53.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=christoph.bauer@lms-gmbh.de \
    --cc=damien.doligez@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).