Created
October 30, 2013 13:01
-
-
Save EightAndAHalfTails/7232295 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
#! /usr/bin/env python3 | |
# Warning: Hackish maths | |
# I sure wish I knew Haskell | |
# Grass always greener? | |
tx = 100e-6 | |
tc = 2e-6 | |
tu = 5e-6 | |
ideal = False | |
lengths = range(1, 33) | |
def lam(k, n): | |
return (n-k) * (1/tx) | |
def r(k): | |
if ideal: | |
return 1/(tc + tu) | |
else: | |
return 1/(tc + tu*(k-1)/2) | |
def eachState(n): | |
return range(n+1) # 0, 1, ... n-1, n | |
def solve(n): | |
p = list() | |
p.append(1) | |
for i in eachState(n): | |
if i > 0: | |
p.append( p[i-1]*lam(i-1, n)/r(i) ) | |
return normalise(p) | |
def normalise(p): | |
return [ x/sum(p) for x in p ] | |
def Nq(n, p): | |
result = 0 | |
for s in range(2, n+1): | |
result += s-1 * p[s] | |
return result | |
def thru(n, p): | |
result = 0 | |
for i in range(1, n+1): | |
result += p[i] * r(i) | |
return result | |
def waiting(n, p): | |
return Nq(n, p) / thru(n, p) | |
def N(n, p): | |
cores = 0 | |
for s in eachState(n): | |
cores += s*p[s] | |
return cores | |
def speedup(n, p): | |
return n-N(n, p) | |
def getGraph(x, i): | |
global tx | |
tx = x | |
global ideal # if only it were that easy... | |
ideal = i | |
w = [] | |
s = [] | |
for n in lengths: | |
p = solve(n) | |
w.append(waiting(n, p)) | |
s.append(speedup(n, p)) | |
#print(w) | |
print(s) | |
getGraph(100e-6, False) | |
getGraph(300e-6, False) | |
getGraph(500e-6, False) | |
getGraph(100e-6, True) | |
getGraph(300e-6, True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment