Last active
July 21, 2022 00:47
-
-
Save navyxliu/29b763d296f84858e7aebfc3a1c90819 to your computer and use it in GitHub Desktop.
scores.rb
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
#!/usr/bin/env ruby | |
# do the statistics of renaissance results | |
# | |
# probably should choose gem 'enumerable-statistics' in the future. | |
# so far, we only need simple procedures. | |
# | |
def median(a) | |
copy = a.sort | |
return copy[a.size / 2] | |
end | |
def mean(a) | |
return a.inject(0.0, :+) / a.size | |
end | |
# standard deviation | |
# treat 'a' is a sample, so use N-1 correction | |
def stddev(a) | |
avg = mean(a) | |
sum = a.inject(0.0) { |sum, e| sum + (e - avg) ** 2 } | |
variance = sum / (a.size - 1) | |
std = Math.sqrt(variance) | |
end | |
WARMUP_ITER = 3 | |
def renassance_result(output) | |
results = [] | |
output.each do |line| | |
# ====== chi-square (apache-spark) [default], iteration 57 completed (795.509 ms) ====== | |
line.match /iteration \d+ completed \((\d+\.\d+) ms\)/ do |m| | |
#puts line, m[1] | |
results << m[1].to_f | |
end | |
end | |
#puts "warmup #{WARMUP_ITER} iterations" | |
# drop first WARMUP_ITER results | |
results.shift WARMUP_ITER | |
printf "means = %.3f, stddev = %.3f, median = %.3f\n", mean(results), stddev(results), median(results) | |
end | |
if $0 == __FILE__ | |
output = ARGF.readlines | |
renassance_result output | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment