caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Lazy vs closure
@ 2004-05-19  6:21 Vladimir N. Silyaev
  2004-05-19  7:04 ` David Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Vladimir N. Silyaev @ 2004-05-19  6:21 UTC (permalink / raw)
  To: caml-list; +Cc: Kenneth Knowles

[-- Attachment #1: Type: text/plain, Size: 685 bytes --]

After reading list and seeing statement that lazy/Lazy.force is faster then
closure/apply, I've decided to run microbenchmark with both.
Results are rather confusing:
 Byte code - Lazy is three times slower than closure
 Native code (x86) - it's either coredumps or leaks memory

Code attached as <<lazy.ml>>. With it's current form native code
leaks memory, by uncommenting first two lines it would coredump.

Also both compilers tends to generate rather strange error.
=-=-=-=-=-=
The files lazy.cmi and lazy.cmi make inconsistent assumptions
over interface Lazy
=-=-=-=-=-=
This error fixable by removing lazy.cmi from a disk.

Have I stepped on some known bug/feature?

Vladimir



[-- Attachment #2: lazy.ml --]
[-- Type: text/plain, Size: 490 bytes --]

(* Uncomment me
let l = lazy (1+1)

let _ = Lazy.force l
*)

let fixit = ref 0


let test_lazy n = 
  let l = lazy (n+1) in
   fixit := Lazy.force l

let test_closure n = 
  let c  = (fun _ -> n+1) in
    fixit := c ()

let test n test = 
  let start = Sys.time () in
    for i=0 to n do
       test i
    done;
    (Sys.time ()) -. start

let result = 
  List.map (test 1000000) [test_lazy; test_closure]


let _ = List.iter print_endline (List.map string_of_float result)
  
     
    



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

end of thread, other threads:[~2004-05-19 13:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-19  6:21 [Caml-list] Lazy vs closure Vladimir N. Silyaev
2004-05-19  7:04 ` David Brown
2004-05-19  7:32   ` Vladimir N. Silyaev
2004-05-19  7:59     ` David Brown
2004-05-19  9:10 ` skaller
2004-05-19 13:11   ` Kenneth Knowles
2004-05-19 13:09 ` [Caml-list] " Kenneth Knowles

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