caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Strange performances
@ 2008-01-18  1:32 Benjamin Canou
  2008-01-18  2:15 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 15+ messages in thread
From: Benjamin Canou @ 2008-01-18  1:32 UTC (permalink / raw)
  To: OCaml

  Hi,

The code following my message is way faster in bytecode than in native
code. Is there a good reason for that or is it a bug ?
Note : It is a (way too, I know) naive implementation of the well known
string suite 1, 11, 21, 1211, 111221, ...

  Benjamin Canou.

=== code ===

let list_of_string s =
  let rec list_of_string s i =
    try s.[i] :: list_of_string s (succ i)
    with _ -> []
  in list_of_string s 0

let rec trans = function
  | '1' :: '1' :: '1' :: tl -> "31" ^ trans tl
  | '1' :: '1' :: tl -> "21" ^ trans tl
  | '1' :: tl -> "11" ^ trans tl
  | '2' :: '2' :: '2' :: tl -> "32" ^ trans tl
  | '2' :: '2' :: tl -> "22" ^ trans tl
  | '2' :: tl -> "12" ^ trans tl
  | '3' :: '3' :: '3' :: tl -> "33" ^ trans tl
  | '3' :: '3' :: tl -> "23" ^ trans tl
  | '3' :: tl -> "13" ^ trans tl
  | [] -> ""
  | _ -> failwith "bad input"

let rec print n s =
  print_endline s ;
  if n > 0 then print (pred n) (trans (list_of_string s))
    
let _ = print 30 "1"

=== perfs ===

benjamin@benjamin-laptop:~/Work/Stuff$ ocamlopt 123.ml -o 123
benjamin@benjamin-laptop:~/Work/Stuff$ time ./123
[...]
real    0m5.245s
user    0m4.944s
sys     0m0.016s
benjamin@benjamin-laptop:~/Work/Stuff$ ocamlc 123.ml -o 123
benjamin@benjamin-laptop:~/Work/Stuff$ time ./123
[...]
real    0m1.097s
user    0m0.840s
sys     0m0.008s
benjamin@benjamin-laptop:~/Work/Stuff$ ocaml -version
The Objective Caml toplevel, version 3.09.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-01-24 22:48 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-18  1:32 Strange performances Benjamin Canou
2008-01-18  2:15 ` [Caml-list] " Jacques Garrigue
2008-01-18  2:28   ` Jacques Garrigue
2008-01-18  7:39   ` Till Varoquaux
2008-01-18  9:12     ` Jacques Garrigue
2008-01-18 16:55       ` Benjamin Canou
2008-01-18 17:05         ` Olivier Andrieu
2008-01-18 17:11           ` Jon Harrop
2008-01-18 17:43         ` Jon Harrop
2008-01-18 19:53           ` Benjamin Canou
2008-01-18 16:55       ` Edgar Friendly
2008-01-18 17:52         ` Kuba Ober
2008-01-18 17:56           ` Jon Harrop
2008-01-19  2:32         ` Jacques Garrigue
2008-01-24 22:52           ` Christophe Raffalli

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).