|
|
|
|
|
by mden
3925 days ago
|
|
I was curious about whether using a vector over list would have any effect even though the size is so small and the answer seems no (I guess as it could be expected). It seems like the listed OCaml program has a default level of 9 where as the C++ one uses 6? Times using original listing (minus print stmts): $ time ./ray-cpp
real 0m3.369s
user 0m3.347s
sys 0m0.010s
$ time ./ray-ml
real 0m4.710s
user 0m4.703s
sys 0m0.003s
Time after changing the 9 in the ocaml program to a six: $ time ./ray-ml
real 0m4.032s
user 0m4.026s
sys 0m0.003s
Seems like C++ has a good edge. Above was ran on a 64 bit machine. |
|
Lastly the virtual call again has the chance to cache miss(although probably only once seeing as we've just got a few impls).
In a small example like this there's a good chance that most of the heap allocations are close together but put this approach into production and you can very easily see fragmentation start driving up your cache misses.
(FWIW I'd also store radius*radius on creation, use a BSP/kd-tree and all sorts of other tricks that really help in these types of computations).