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

* Re: [Caml-list] Lazy vs closure
  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  9:10 ` skaller
  2004-05-19 13:09 ` [Caml-list] " Kenneth Knowles
  2 siblings, 1 reply; 7+ messages in thread
From: David Brown @ 2004-05-19  7:04 UTC (permalink / raw)
  To: Vladimir N. Silyaev; +Cc: caml-list, Kenneth Knowles

On Tue, May 18, 2004 at 11:21:57PM -0700, Vladimir N. Silyaev wrote:

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

Your module name is the same as the Lazy module that you're trying to
use.  Rename your program to something else and see if that gets rid of
the problem.

Dave Brown

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


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

* Re: [Caml-list] Lazy vs closure
  2004-05-19  7:04 ` David Brown
@ 2004-05-19  7:32   ` Vladimir N. Silyaev
  2004-05-19  7:59     ` David Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Vladimir N. Silyaev @ 2004-05-19  7:32 UTC (permalink / raw)
  To: David Brown; +Cc: caml-list, Kenneth Knowles

On Wed, May 19, 2004 at 12:04:20AM -0700, David Brown wrote:
> > 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.
> 
> Your module name is the same as the Lazy module that you're trying to
> use.  Rename your program to something else and see if that gets rid of
> the problem.
Good catch!! It get rid of initial problem, but another issue came up:
-=-=-=-
> ocamlopt.opt -v
The Objective Caml native-code compiler, version 3.07+2
Standard library directory: /usr/local/lib/ocaml
>ocamlopt.opt lazy_test.ml
Files lazy_test.cmx and /usr/local/lib/ocaml/stdlib.cmxa
make inconsistent assumptions over implementation Lazy
-=-=-=-

Same error on MinGW (binary installation) and on FreeBSD (compiled from
the source code).

--
Vladimir

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


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

* Re: [Caml-list] Lazy vs closure
  2004-05-19  7:32   ` Vladimir N. Silyaev
@ 2004-05-19  7:59     ` David Brown
  0 siblings, 0 replies; 7+ messages in thread
From: David Brown @ 2004-05-19  7:59 UTC (permalink / raw)
  To: Vladimir N. Silyaev; +Cc: David Brown, caml-list, Kenneth Knowles

On Wed, May 19, 2004 at 12:32:47AM -0700, Vladimir N. Silyaev wrote:

> Files lazy_test.cmx and /usr/local/lib/ocaml/stdlib.cmxa
> make inconsistent assumptions over implementation Lazy

Did you delete all of the lazy.* files (especially lazy.cmi)?

Dave

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


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

* Re: [Caml-list] Lazy vs closure
  2004-05-19  6:21 [Caml-list] Lazy vs closure Vladimir N. Silyaev
  2004-05-19  7:04 ` David Brown
@ 2004-05-19  9:10 ` skaller
  2004-05-19 13:11   ` Kenneth Knowles
  2004-05-19 13:09 ` [Caml-list] " Kenneth Knowles
  2 siblings, 1 reply; 7+ messages in thread
From: skaller @ 2004-05-19  9:10 UTC (permalink / raw)
  To: Vladimir N. Silyaev; +Cc: caml-list, Kenneth Knowles

On Wed, 2004-05-19 at 16:21, Vladimir N. Silyaev wrote:
> After reading list and seeing statement that lazy/Lazy.force is faster then
> closure/apply, I've decided to run microbenchmark with both.

Is there any difference semantically?

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



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


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

* [Caml-list] Re: Lazy vs closure
  2004-05-19  6:21 [Caml-list] Lazy vs closure Vladimir N. Silyaev
  2004-05-19  7:04 ` David Brown
  2004-05-19  9:10 ` skaller
@ 2004-05-19 13:09 ` Kenneth Knowles
  2 siblings, 0 replies; 7+ messages in thread
From: Kenneth Knowles @ 2004-05-19 13:09 UTC (permalink / raw)
  To: Vladimir N. Silyaev; +Cc: caml-list


Your test_lazy creates a new lazy value each time.  The thing that might make
Lazy faster than closure (or rather, _should_ make it faster) is if you evaluate
the same value multiple times, because it is only computed once.  The slowdown
compared to closures is probably the bookkeeping necessary for this memoizing.

Kenn

On Tue, May 18, 2004 at 11:21:57PM -0700, Vladimir N. Silyaev wrote:
> 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

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


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

* Re: [Caml-list] Lazy vs closure
  2004-05-19  9:10 ` skaller
@ 2004-05-19 13:11   ` Kenneth Knowles
  0 siblings, 0 replies; 7+ messages in thread
From: Kenneth Knowles @ 2004-05-19 13:11 UTC (permalink / raw)
  To: skaller; +Cc: Vladimir N. Silyaev, caml-list


On Wed, May 19, 2004 at 07:10:21PM +1000, skaller wrote:
> Is there any difference semantically?

Yes, since lazy values are not recomputed.

# let l = lazy (print_string "hello");;
val l : unit lazy_t = <lazy>
# Lazy.force l;;
hello- : unit = ()
# Lazy.force l;;
- : unit = ()

Kenn

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


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