4 ms·
You didn't test with a static array, though: let insert_array_test () = let result = ref 0 in for i = 1 to iterations do let work = Arr
by junke 9y ago
You didn't test with a static array, though:
let insert_array_test () =
let result = ref 0 in
for i = 1 to iterations do
let work = Array.make count 0 in
for j = 1 to count do
Array.set work (j - 1) j
done;
result := !result + Array.length work
done;
!result
I have the following numbers:
# main ();;
linked lists 2.983 seconds
linked lists (rec) 2.827 seconds
dynamic arrays 5.152 seconds
static arrays 1.718 seconds
- rbehrends 9y agoYes, I was assuming a case where you don't know exactly how much memory you know ahead of time. If you have predictable requirements, you can just use stack allocations. For example, note how the `ref 0` in the code does not actually incur overhead; the compiler does escape analysis and will stuff the counter in a register or stack location.