From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id D4223BB81 for ; Sun, 8 Jan 2006 18:45:08 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k08Hj8TL018669 for ; Sun, 8 Jan 2006 18:45:08 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA07558 for ; Sun, 8 Jan 2006 18:45:07 +0100 (MET) Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.194]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k08Hj70r018664 for ; Sun, 8 Jan 2006 18:45:07 +0100 Received: by uproxy.gmail.com with SMTP id q2so1110188uge for ; Sun, 08 Jan 2006 09:45:07 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:reply-to:user-agent:x-accept-language:mime-version:to:subject:content-type:from; b=UtNuKV5COCKqPzygEegGbylHTWXPWwlYZQXF9viAGTCdOUHeMPrFMyPTYTYt8w+KvobfP2Iw0eQSQ2o4miy19yv4ixFsmpzGczVs4JixmVdXf5Zg99fpWoJ0xUCgf+r9Xlqg3JF3ew+XffNvF3riSI02Vt9ALauHQsKpxkdr2Z8= Received: by 10.67.27.10 with SMTP id e10mr7185031ugj; Sun, 08 Jan 2006 09:45:06 -0800 (PST) Received: from ?192.168.1.10? ( [88.137.85.205]) by mx.gmail.com with ESMTP id q40sm6819356ugc.2006.01.08.09.45.05; Sun, 08 Jan 2006 09:45:05 -0800 (PST) Message-ID: <43C14FA5.9060502@laposte.net> Date: Sun, 08 Jan 2006 18:45:09 +0100 Reply-To: matthieu.dubuget@laposte.net User-Agent: Mozilla Thunderbird 1.0.2 (X11/20051002) X-Accept-Language: fr, en MIME-Version: 1.0 To: Caml List Subject: Shootout again - chameneos Content-Type: multipart/mixed; boundary="------------080803090300070201030807" From: Matthieu Dubuget X-Miltered: at nez-perce with ID 43C14FA4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 43C14FA3.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; matthieu:01 dubuget:01 matthieu:01 dubuget:01 compilation:01 ocamlopt:01 -noassert:01 -unsafe:01 cmxa:01 threads:01 cmxa:01 val:01 val:01 rec:01 pred:01 X-Attachments: name="chameneos.ml" name="chameneos.ml" X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 This is a multi-part message in MIME format. --------------080803090300070201030807 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------080803090300070201030807 Content-Type: text/plain; name="chameneos.ml" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="chameneos.ml" (* * * 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 () --------------080803090300070201030807--