Browse thread
How to read different ints from a Bigarray?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Goswin von Brederlow <goswin-v-b@w...> |
| Subject: | Re: [Caml-list] Re: How to read different ints from a Bigarray? |
Sylvain Le Gall <sylvain@le-gall.net> writes:
> On 29-10-2009, Goswin von Brederlow <goswin-v-b@web.de> wrote:
>> Xavier Leroy <Xavier.Leroy@inria.fr> writes:
>>> Goswin von Brederlow wrote:
>>
>> Here are some benchmark results:
>>
>> get an int out of a string:
>> C Ocaml
>> uint8 le 19.496 17.433
>> int8 le 19.298 17.850
>> uint16 le 19.427 25.046
>> int16 le 19.383 27.664
>> uint16 be 20.502 23.200
>> int16 be 20.350 27.535
>>
>> get an int out of a Bigarray.Array1.t:
>> safe unsafe
>> uint8 le 55.194s 54.508s
>> uint64 le 80.51s 81.46s
>>
>
> Can you provide us with the corresponding code and benchmark?
>
> Maybe you can just commit this in libaio/test/bench.ml.
>
> Regards,
> Sylvain Le Gall
As Christophe guessed the problem was polymorphic functions. If I
specify a fixed Array1 type then the compiler uses the optimized
access functions. Makes unsafe Bigarray slightly faster than unsafe
string actually (must not optimize int_of_char/Char.unsafe_chr away)
and that independent of argument size (on set, on get allocating
int32/int64 costs time so they are slower).
So Bigarray is the fastest but getting different types out of a
Bigarray will be tricky. Unaligned even more so if not impossible.
I have to sleep on this. Maybe in my use case I can have all
structures int64 aligned and then split the int64 up in ocaml where
structures have smaller members. Would have been too much to have a
Bigarray with access functions for any type. Maybe some little wrapper
with Obj.Magic will do *hide*.
As for libaio it should be easy to make it create and use any Bigarray
type.
MfG
Goswin