4 ms·
I guess both Java and OCaml will see that the object can be generated on the stack which makes it much faster. By using malloc in the C implementation, you for
by albertzeyer 16y ago
I guess both Java and OCaml will see that the object can be generated on the stack which makes it much faster.
By using malloc in the C implementation, you force it to be on the heap.
- thelema314 16y agoActually, OCaml never generates objects like this on the stack - value creation is always taken literally. The OCaml compiler is really allocating all those records. It's just that their lifetime is almost zero, so the cost to clean them up is zero (as none get promoted from the minor heap to the major heap). And the cost to create them is almost zero, just a += and a compare.
- albertzeyer 16y agoAh, interesting. Does it also have a GC or some own custom allocation implementation? Because if it really would use something like malloc, I don't really see how it should be faster than the C version.