From: Markus Mottl <markus@oefai.at>
To: Christophe TROESTLER <debian00@tiscalinet.be>
Cc: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] The invert Benchmark
Date: Wed, 17 Apr 2002 22:30:39 +0200 [thread overview]
Message-ID: <20020417203039.GA3339@fichte.ai.univie.ac.at> (raw)
In-Reply-To: <20020417.202615.87280210.debian00@tiscalinet.be>
On Wed, 17 Apr 2002, Christophe TROESTLER wrote:
> I found by chance the "The invert Benchmark"
> (http://www.lib.uchicago.edu/keith/crisis/benchmarks/invert/). As you
> will notice the Caml code (even compiled) performs poorly.
Looking at the code this does not surprise me...
> Anybody got better ideas to improve efficiency? Could a "keys"
> function be an interesting addition to Hashtbl???
This should be about 10x faster than the initial version:
---------------------------------------------------------------------------
let report_url url = print_string ("\t" ^ url)
let report (file, url_lst) =
let url_ar = Array.of_list url_lst in
Array.sort compare url_ar;
print_string file; Array.iter report_url url_ar; print_char '\n'
let _ =
let table = Hashtbl.create 10000 in
let cnt_ref = ref 0 in
try
while true do
let line = input_line stdin in
let ix = String.index line '\t' in
let url = String.sub line 0 ix in
let file = String.sub line (ix + 1) (String.length line - ix - 1) in
try
let urls_ref = Hashtbl.find table file in
urls_ref := url :: !urls_ref
with Not_found -> incr cnt_ref; Hashtbl.add table file (ref [url])
done
with
| End_of_file ->
let ar = Array.make !cnt_ref ("", []) in
let coll file urls_ref cnt = ar.(cnt) <- file, !urls_ref; cnt - 1 in
ignore (Hashtbl.fold coll table (!cnt_ref - 1));
Array.sort compare ar; Array.iter report ar
| Not_found -> failwith "bad data"
---------------------------------------------------------------------------
> Another related question that popped up is: how to _efficiently_
> implement a join operation (join : string -> string list -> string is
> defined by: join c [s1;...;sn] = s1 ^ c ^ ... ^ c ^ sn) ?
Look up the function "String.concat" in the standard library...
Regards,
Markus Mottl
--
Markus Mottl markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2002-04-17 20:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-17 18:26 Christophe TROESTLER
2002-04-17 20:04 ` Xavier Leroy
2002-04-17 20:28 ` Nadji.Gauthier
2002-04-18 19:07 ` [Caml-list] " Christophe TROESTLER
2002-04-18 19:21 ` Mattias Waldau
2002-04-17 20:13 ` [Caml-list] " Remi VANICAT
2002-04-17 20:30 ` Markus Mottl [this message]
2002-04-17 21:19 ` Mattias Waldau
2002-04-18 9:11 ` Jean-Christophe Filliatre
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=20020417203039.GA3339@fichte.ai.univie.ac.at \
--to=markus@oefai.at \
--cc=caml-list@inria.fr \
--cc=debian00@tiscalinet.be \
/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