From: Matthieu Dubuget <matthieu.dubuget@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: Shootout again - chameneos
Date: Sun, 08 Jan 2006 18:45:09 +0100 [thread overview]
Message-ID: <43C14FA5.9060502@laposte.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 269 bytes --]
Hello.
I attach an implementation for one of the new shootout test.
http://shootout.alioth.debian.org/debian/benchmark.php?test=chameneos&lang=all
It is based on the mlton's implementation.
Any idea/suggestion to improve it's speed ?
Thanks in advance.
Matthieu
[-- Attachment #2: chameneos.ml --]
[-- Type: text/plain, Size: 1722 bytes --]
(*
*
* The Great Computer Language Shootout
* http://shootout.alioth.debian.org/
*
* compilation: ocamlopt -noassert -unsafe -ccopt -O3 unix.cmxa threads.cmxa chameneos.ml
*
* Contributed by Matthieu Dubuget
*)
(* color manipulation *)
type color = Blue | Red | Yellow
(* val compl : color * color -> color *)
let compl = function
| Blue, Blue | Red, Yellow | Yellow, Red -> Blue
| Blue, Red | Red, Blue | Yellow, Yellow -> Yellow
| Blue, Yellow | Yellow, Blue | Red, Red -> Red
(* val place : int -> ('a option Event.channel * 'a) Event.channel *)
let place n =
let chan = Event.new_channel () in
let ev = Event.receive chan in
let rec lp n =
let ch1, c1 = Event.sync ev in
match n with
| 0 -> Event.sync (Event.send ch1 None); lp 0
| n -> let ch2, c2 = Event.sync ev in
ignore (Event.sync(Event.send ch1 (Some c2)));
ignore (Event.sync(Event.send ch2 (Some c1)));
lp (pred n) in
ignore( Thread.create lp n );
chan
(* val animal :
(color option Event.channel * color) Event.channel ->
int Event.channel -> color -> unit *)
let animal p m c =
let a = Event.new_channel () in
let rec lp n c =
Event.sync( Event.send p (a, c));
match Event.sync (Event.receive a) with
None -> ignore (Event.sync (Event.send m n))
| Some oc -> lp (succ n) (compl (c, oc)) in
ignore(Thread.create (lp 0) c)
(* val go : int -> int *)
let go n =
let p = place n
and m = Event.new_channel () in
let colors = [Blue; Red; Yellow; Blue] in
List.iter (animal p m) colors;
List.fold_left (fun s c -> s + Event.sync (Event.receive m)) 0 colors
let main () =
let n = go (int_of_string Sys.argv.(1)) in
print_int n; print_newline () ;;
main ()
reply other threads:[~2006-01-08 17:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=43C14FA5.9060502@laposte.net \
--to=matthieu.dubuget@gmail.com \
--cc=caml-list@inria.fr \
--cc=matthieu.dubuget@laposte.net \
/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