Created
May 2, 2018 03:53
-
-
Save paniq/caa074a4f73723fd8e7fa6305436d42b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using import ..tukan.random | |
fn main () | |
let rnd = (static (Random 32)) | |
'seed rnd | |
fn test-factor (factor) | |
print "factor" factor | |
let iters = 100000 | |
let total-wasted total-allocs = | |
local f64 0 | |
local i32 0 | |
for k in (range iters) | |
let wasted capacity count allocs copied = | |
local i32 1 | |
local i32 1 | |
local i32 0 | |
local i32 0 | |
local i32 0 | |
let q = 10000.0 | |
let a = | |
log2 q | |
let b = | |
log2 (factor * q - 1.0) | |
let total = | |
a + (b - a) * ('random rnd f32) | |
let total = | |
i32 (2.0 ** total) | |
for i in (range total) | |
count += 1 | |
if (count > capacity) | |
wasted += capacity | |
capacity = | |
i32 | |
(f32 capacity) * factor + 0.5 | |
allocs += 1 | |
deref allocs | |
"allocs" | |
deref wasted | |
"wasted," | |
deref capacity | |
"capacity" | |
#print "overhead" | |
wasted + capacity - total | |
total-wasted += | |
(wasted + capacity) / total | |
total-allocs += allocs | |
print "wasted:" | |
f32 (total-wasted / (f64 iters)) | |
#print "allocs:" | |
total-allocs / iters | |
print; | |
test-factor 2.0 | |
test-factor 2.5 | |
test-factor e | |
test-factor 2.9 | |
test-factor 3.0 | |
test-factor 4.0 | |
# | |
test-factor 1.5 | |
test-factor 2.0 | |
test-factor 3.0 | |
test-factor 4.0 | |
test-factor 8.0 | |
test-factor 16.0 | |
test-factor 32.0 | |
test-factor 64.0 | |
test-factor 128.0 | |
define bleh | |
compile | |
typify main | |
'O3 | |
bleh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment