Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Loop times
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabrice Le Fessant <fabrice@l...>
Subject: Re: [Caml-list] Loop times

>  
>  	OK, I just did a test of the three methods.  Here's the code:
>  
>  Exception Version:
>  -------------------------------------------------
>  exception Break
>  
>  let _ =
>    let ary = [|1;2;3;4;5;6;7;8;9;10;11;12|] in
>      for i = 1 to 1_000_000_000 do
>        try
>          for j = 1 to 10 do
>            if ary.(j) = 5 then
>              raise Break
>          done
>        with Break -> ()
>      done
>  
>  real    0m30.569s
>  user    0m30.250s
>  sys     0m0.140s
>  ------------------------------------------------------

For the fun, could you try this one ? It does not allocate the
exception in the loop but outside.

  -------------------------------------------------
 exception Break
 
 let _ =
   let ary = [|1;2;3;4;5;6;7;8;9;10;11;12|] in
   let exn = Break in
     for i = 1 to 1_000_000_000 do
       try
         for j = 1 to 10 do
           if ary.(j) = 5 then
             raise exn
         done
       with Break -> ()
     done 
 ------------------------------------------------------
 


- Fabrice

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