Instantly share code, notes, and snippets.

Embed
What would you like to do?
BENCHES = {
binary_trees: {
c: 3.73,
cs: 7.73,
cpp: 3.68,
go: 28.82,
java: 8.39,
rust: 4.10,
},
fannkuch_redux: {
c: 8.67,
cs: 17.46,
cpp: 10.12,
go: 17.82,
java: 17.98,
rust: 10.13,
},
fasta: {
c: 1.36,
cs: 2.27,
cpp: 1.33,
go: 2.07,
java: 2.32,
rust: 1.46,
},
k_nucleotide: {
c: 4.88,
cs: 5.48,
cpp: 3.73,
go: 12.09,
java: 8.74,
rust: 5.45,
},
mandelbrot: {
c: 1.64,
cs: 5.54,
cpp: 1.51,
go: 5.47,
java: 6.96,
rust: 1.74,
},
n_body: {
c: 9.37,
cs: 21.41,
cpp: 9.42,
go: 21.00,
java: 22.00,
rust: 5.70,
},
pidigits: {
c: 1.88,
cs: 2.06,
cpp: 1.89,
go: 2.97,
java: 3.13,
rust: 1.75,
},
regex_redux: {
c: 1.46,
cs: 2.22,
cpp: 1.83,
go: 28.99,
java: 10.50,
rust: 2.44,
},
reverse_complement: {
c: 1.76,
cs: 2.99,
cpp: 2.93,
go: 4.00,
java: 3.32,
rust: 1.62,
},
spectral_norm: {
c: 1.98,
cs: 4.07,
cpp: 1.98,
go: 3.98,
java: 4.26,
rust: 1.97,
}
}
MEMORY = {
binary_trees: {
c: 116600,
cs: 809848,
cpp: 119052,
go: 463464,
java: 960056,
rust: 199760,
},
fannkuch_redux: {
c: 852,
cs: 34728,
cpp: 1852,
go: 1472,
java: 31180,
rust: 916,
},
fasta: {
c: 2864,
cs: 68140,
cpp: 1740,
go: 2620,
java: 42212,
rust: 2008,
},
k_nucleotide: {
c: 130060,
cs: 186672,
cpp: 156080,
go: 158320,
java: 470116,
rust: 135028,
},
mandelbrot: {
c: 26512,
cs: 66356,
cpp: 25640,
go: 31004,
java: 76316,
rust: 32472,
},
n_body: {
c: 1088,
cs: 36520,
cpp: 1704,
go: 1536,
java: 32272,
rust: 916,
},
pidigits: {
c: 2720,
cs: 38564,
cpp: 4380,
go: 8520,
java: 97364,
rust: 3036,
},
regex_redux: {
c: 152216,
cs: 295364,
cpp: 203520,
go: 338504,
java: 571736,
rust: 199876,
},
reverse_complement: {
c: 994488,
cs: 1035748,
cpp: 980716,
go: 826728,
java: 609712,
rust: 994780,
},
spectral_norm: {
c: 1168,
cs: 35988,
cpp: 1164,
go: 2656,
java: 33572,
rust: 2204,
}
}
def summary_by_lang(benches, floor: 0.0)
stats = stats_by_lang(benches, floor: floor)
summary = stats.each_pair.with_object({}) do |(lang, times), summary|
summary[lang] = avg(times)
end
summary.sort_by { |_lang, times| times }.to_h
end
def stats_by_lang(benches, floor: 0.0)
benches.each_pair.with_object({}) do |(name, bench), times|
stats = stats_for_bench(bench, floor: floor)
stats.each_pair do |lang, time|
times[lang] ||= []
times[lang] << time
end
end
end
def stats_for_bench(bench, floor: 0.0)
best_time = [floor, bench.values.sort.first.to_f].max
bench.each_pair.with_object({}) do |(lang, time), stats|
ratio = [floor, time.to_f].max / best_time
stats[lang] = ratio
end
end
def avg(array)
array.inject { |sum, el| sum + el }.to_f / array.size
end
def print_summary(data, floor: 0.0)
summary = summary_by_lang(data, floor: floor)
summary_stats = stats_for_bench(summary, floor: 0.0)
summary_stats.each_pair do |lang, summary|
puts " #{lang}: #{summary.round(4)}"
end
puts "\n"
end
puts " Time score:"
print_summary(BENCHES)
puts " Memory score (no floor):"
print_summary(MEMORY)
puts " Memory score (floor 50k):"
print_summary(MEMORY, floor: 50000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment