Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml Bigarray: slower than builtin arrays?

What are the downsides of using Bigarray when interfacing with C is not an issue? Are they slower, in particular for small 2D matrices?

like image 660
lukstafi Avatar asked Oct 29 '12 15:10

lukstafi


2 Answers

Just based on looking through the implementations, I'd say that bigarrays might be slower if you create large numbers of short-lived arrays. It looks like the memory for them is managed outside the usual OCaml GC, which handles short-lived objects extremely well.

You also might find that accesses to bigarrays aren't inlined, whereas accesses to the built-in arrays would be.

On the other hand, built-in arrays are going to have an extra indirection for two-dimensions.

If the performance really matters, you'll probably have to benchmark your particular application.

like image 173
Jeffrey Scofield Avatar answered Nov 15 '22 09:11

Jeffrey Scofield


The main downside is right there in the type - bigarrays can hold only small subset of primitive types

like image 24
ygrek Avatar answered Nov 15 '22 08:11

ygrek