Version française
Home     About     Download     Resources     Contact us    
Browse thread
Performance questions, -inline, ...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Kuba Ober <ober.14@o...>
Subject: Re: [Caml-list] Performance questions, -inline, ...
> how about:
>
> (* generic vector operation *)
> let op2 op a b nloop =
> 	let len = Array.length a in
> 	for j = 0 to nloop do
> 		for i = 0 to len-1 do
> 			b.(i) <- op a.(i) b.(i)
> 		done;
> 	done
>
> let add4 = op2 (+.)

This doesn't change a thing, as I've said the code is part
of a larger benchmark, that's why there are some unused parameters
etc. They have no effect on performance.

> Why does your code have the j loops?

Simply to execute the operation Array.length ^ 2 times :)

> You add a constant (or vector 
> element) a number of times equal to the length of your vector?

No, equal to the square of it. I didn't want to have too big vectors. The
stuff executes floor(sqrt(50e6)) times.

> Arrays of floats have some optimizations built in to the compiler (no
> boxing, even though they're not 31-bit values), so you should get as
> good performance as you'll get.

Are you saying that it may be faster to use a one-element array than a ref? 
That'd be curious at best, and a WTF otherwise ;)

Cheers, Kuba