diff options
author | Ori Bernstein <ori@eigenstate.org> | 2014-08-15 15:29:37 -0400 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2014-08-15 15:29:37 -0400 |
commit | b7d4386bf0a35245a2d8705d379aa68d56ea0dbe (patch) | |
tree | 2b7ecf9e694504efa8776cd2b245b220daf363e3 /bench | |
parent | 52af0fabaa1b7b36a1848f53b1abb4538dcebabc (diff) | |
download | mc-b7d4386bf0a35245a2d8705d379aa68d56ea0dbe.tar.gz |
Add shuffled alloc/free to the alloc test.
Diffstat (limited to 'bench')
-rw-r--r-- | bench/copious-allocs.myr | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bench/copious-allocs.myr b/bench/copious-allocs.myr index 091b83b..886adde 100644 --- a/bench/copious-allocs.myr +++ b/bench/copious-allocs.myr @@ -24,5 +24,29 @@ const main = { for i = a.len; i > 0; i-- std.free(a[i - 1]) ;; + + /* alloc forwards, dealloc randomly */ + for i = 0; i < a.len; i++ + a[i] = std.alloc() + ;; + shuffle(a[:]) + for i = a.len; i > 0; i-- + std.free(a[i - 1]) + ;; ;; } + +const shuffle = {a + var t + var rng + var i, j + + rng = std.mksrng(123) + for i = 0; i < a.len - 1; i++ + j = std.rand(rng, i, a.len) + t = a[j] + a[j] = a[i] + a[i] = t + ;; +} + |