Last active
February 27, 2018 02:40
-
-
Save juestr/fce0da0c981513589dc1247a5f3a63d7 to your computer and use it in GitHub Desktop.
expected blocktime by random time selection
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
#!/usr/bin/env python3 | |
from numpy import * | |
nblocks = 10000 | |
nsamples= 10000 | |
def random_block_duration(_acc=1, _steps=512): | |
nz = nonzero(random.poisson(1/600., size=_steps))[0] | |
return _acc + nz[0] if len(nz) else random_block_duration(_acc + _steps, _steps) | |
intervals = array([random_block_duration() for _ in range(nblocks)]) | |
block_times = cumsum(intervals) | |
def block_length_at_time(t): | |
return intervals[searchsorted(block_times, t)] | |
sample_times = random.random(size=nsamples) * block_times[-1] | |
sample_lengths = vectorize(block_length_at_time)(sample_times) | |
def p(what, xs): | |
print('%d %s, average = %f seconds, min = %f, max = %f' % | |
(len(xs), what, average(xs), min(xs), max(xs))) | |
p('blocks created', intervals) | |
p('times sampled', sample_lengths) | |
-- | |
~/work/blocktime/% ./blocktime.py | |
1000 blocks created, average = 620.926000 seconds, min = 4.000000, max = 4677.000000 | |
10000 times sampled, average = 1181.791000 seconds, min = 6.000000, max = 4677.000000 | |
~/work/blocktime/% ./blocktime.py | |
1000 blocks created, average = 613.377000 seconds, min = 1.000000, max = 4307.000000 | |
10000 times sampled, average = 1230.157100 seconds, min = 4.000000, max = 4307.000000 | |
~/work/blocktime/% ./blocktime.py | |
1000 blocks created, average = 596.308000 seconds, min = 3.000000, max = 4532.000000 | |
10000 times sampled, average = 1126.356100 seconds, min = 14.000000, max = 4532.000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment