Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Q: float arrays
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jocelyn Serot <jserot@e...>
Subject: Re: Q: float arrays

> [... lots of interesting comments deleted ...]
>
> If you inline the "*." operation in map2, all boxing will be
> eliminated (and all dynamic tests as well, since the function is now
> monomorphic), and you'll get much better performance than what can be
> obtained with an array of pairs:
> 
>  let product f a a' =
>    let l = length a in
>    if ( length a' != l ) then invalid_arg "product" else
>    if l = 0 then [||] else begin
>      let r = create l (f(unsafe_get a 0)(unsafe_get a' 0)) in
>      for i = 1 to l - 1 do
>        unsafe_set r i (unsafe_get a i *. unsafe_get a' i)
>      done;
>      r
>    end

Ok, i tried this. Here are the results:

jserot@tufa$ omain
 Number of samples is 1683
 Each sample counts as 0.02 seconds.

 %       self     self&            self    total
 time    seconds  children  calls  ms/call ms/call name
-------------------------------------------------------
63.10   18.527   18.527       11   1.684   1.684   map2
36.24   10.641   10.641       11   0.967   0.967   map_pairs
 0.59    0.174    0.174       11   0.016   0.016   product

Self-demonstrative. 

Thanks for your help,

	Jocelyn
-- 
E-mail: jserot@epcc.ed.ac.uk (->Nov 29 1996) ................................
S-mail: LASMEA - URA 1793 CNRS, Universite Blaise Pascal, 63177 Aubiere cedex
Tel: (33) 73.40.73.30 - Fax: (33) 73.40.72.62 ...............................
.... http://wwwlasmea.univ-bpclermont.fr/Personnel/Jocelyn.Serot/Welcome.html