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: Daniel M. Albro <albro@h...>
Subject: Re: [Caml-list] Loop times

OK, I did this test, but first after making the thing
compatible with the other tests I did.  (That is, the
j loop should be 0 to 9 (or some other number less than
12 and greater than 4).  The first version (once
again, after changing the j loop to 0 to 9) takes

real    0m34.033s
user    0m34.030s
sys     0m0.000s

and Fabrice's version (with 0 to 9) takes

real    0m28.086s
user    0m28.080s
sys     0m0.000s

so it is definitely a win.

					- Dan

Fabrice Le Fessant wrote:
>> 
>> 	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