Created
July 2, 2013 08:03
-
-
Save rahbirul/5907522 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
import math | |
def average(li): | |
return sum(li) * 1.0 / len(li) | |
def stddev(numbers): | |
avg = average(numbers) | |
variance = map(lambda x: (x - avg)**2, numbers) | |
return math.sqrt(average(variance)) | |
def percentile(numbers, percent): | |
k = (len(numbers)-1) * (percent / 100.0) | |
f = math.floor(k) | |
c = math.ceil(k) | |
if f == c: | |
return numbers[int(k)] | |
d0 = numbers[int(f)] * (c-k) | |
d1 = numbers[int(c)] * (k-f) | |
return d0+d1 | |
if __name__ == '__main__': | |
filename = sys.argv[1] | |
numbers = [float(line.replace(' secs', '').strip()) for line in open(filename)] | |
print "Standard Deviation: %f" % stddev(numbers) | |
print "90th percentile: %f" % percentile(numbers, 90) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment