Version française
Home     About     Download     Resources     Contact us    
Browse thread
Optimizing Array.blit
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Re: Optimizing Array.blit
From: "David Baelde" <david.baelde@gmail.com>
> To answer the question by myself, I have ran a few tests. It turned
> out that specializing Array.blit provides a significant boost, but
> doing such an ugly hack was dangerous and unnecessary. I now use the
> following standard code:
> 
> CAMLprim value caml_float_array_blit(value _src, value _src_off,
>                                      value _dst, value _dst_off, value _len) {
>   int src_off = Int_val(_src_off) ;
>   int dst_off = Int_val(_dst_off) ;
>   int len = Int_val(_len) ;
>   int i ;
>   for (i=0 ; i<len ; i++)
>     Store_double_field(_dst,dst_off+i,Double_field(_src,src_off+i)) ;
>   return Val_unit ;
> }
> 
> I got the following timings in seconds for a program doing intensive
> blits on float arrays: 0.17 for the ugly hack, 0.19 for the clean C
> function, 1.04 for the standard Array.blit.

Did you try taking the version from the standard library, and
annotating it with (a1 : float array)?
No ugly hack here: everything is 100% safe.
Personally, I get a 4 fold improvement just doing that.
Sometimes polymorphism is costly (particularly with arrays.)

Jacques Garrigue