d:alloc_time_test
Code:
import std.stdio; import std.datetime; ubyte[] alloc_test(size_t size) { auto starttime = Clock.currTime(); ubyte[] arr = new ubyte[size]; auto duration = Clock.currTime() - starttime; writeln("size ", size, ", time: ", duration); return arr; } int main(string[] args) { size_t size = 1u; for (;;) { alloc_test(size); size *= 10u; } return 0; }
Output:
$ ./alloc size 1, time: 22 μs and 3 hnsecs size 10, time: 3 μs size 100, time: 2 μs size 1000, time: 10 μs and 6 hnsecs size 10000, time: 539 μs and 7 hnsecs size 100000, time: 195 μs and 5 hnsecs size 1000000, time: 1 ms, 506 μs, and 6 hnsecs size 10000000, time: 15 ms, 566 μs, and 5 hnsecs size 100000000, time: 43 ms, 450 μs, and 9 hnsecs size 1000000000, time: 268 ms, 474 μs, and 2 hnsecs core.exception.OutOfMemoryError@../../../../src/libphobos/libdruntime/core/exception.d(705): Memory allocation failed ----------------
d/alloc_time_test.txt · Last modified: by josh
