Skip to content

Instantly share code, notes, and snippets.

@josh-richardson
Created November 5, 2018 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josh-richardson/cd628b3ebcd4c932f648de054e83b61a to your computer and use it in GitHub Desktop.
Save josh-richardson/cd628b3ebcd4c932f648de054e83b61a to your computer and use it in GitHub Desktop.
it hurts to live, but more
import statistics
import json
# def process_parallel(item):
class BenchmarkResult:
def __init__(self, language, cores, speed, category, computer):
self.language = language
self.cores = cores
self.speed = speed
self.category = category
self.computer = computer
def __str__(self):
return ('%s with %d cores took %s for %s on %d' % (self.language, self.cores, self.speed, self.category, self.computer))
def __eq__(self, other):
"""Overrides the default implementation"""
if isinstance(other, BenchmarkResult):
return self.speed == other.speed and self.language == other.language and self.cores == other.cores and self.computer == other.computer and self.category == other.category
return False
def __hash__(self):
return hash(self.language) ^ hash(self.cores) ^ hash(self.speed) ^ hash(self.category) ^ hash(self.computer)
def get_category_max(self):
return int(self.category.split(" ")[2])
final_results = []
result_types = ["results_c.txt", "results_go.txt", "results_c_parallel.txt", "results_go_parallel.txt"]
result_categories = ["1 and 15000", "1 and 30000", "1 and 60000"]
stoof = {}
for i in range(1, 4):
for j in range(1, 4):
for file in result_types:
filename = 'gpgnode-0%d/0%d/%s' % (i, j, file)
results = open(filename, 'r').read()
if file in stoof:
stoof[file] += "\n" + results
else:
stoof[file] = results
for file in result_types:
individuals = list(filter(lambda x: len(x.strip()) != 0, stoof[file].split("Time for")))
fileseg = (len(individuals)) / 3
counter = 0
computer = 0
for benchmark in individuals:
if (counter % fileseg == 0):
computer += 1
counter += 1
for category in result_categories:
if (category in benchmark):
benchmark_lines = benchmark.split('\n')
language = benchmark_lines[0].split(" ")[2] if ("parallel" in benchmark) else benchmark_lines[0].split(" ")[3]
cores = int(benchmark_lines[0].split(" ")[4]) if ("parallel" in benchmark) else 0
speed = benchmark_lines[4] if language == "go" else benchmark_lines[3]
speed = speed.split(" ")[1].replace("s", "").split("m")
speed = int(1000 * ((60 * int(speed[0])) + float(speed[1]))) / 1000
result = BenchmarkResult(language, cores, speed, category, computer)
final_results.append(result)
# print('%s with %d cores took %s for %s on %s' % (language, cores, speed, category, file))
no_dupes = []
for itm in final_results:
dupes = list(filter(lambda x: x.cores == itm.cores and x.language == itm.language and x.category == itm.category and x.computer == itm.computer, final_results))
wanted_item = list(filter(lambda x: x.speed == statistics.median(map(lambda x: x.speed, dupes)), dupes))[0]
no_dupes.append(wanted_item)
stuff_we_actually_want = (set(no_dupes))
table_items = list(filter(lambda x: x.computer == 1 and x.get_category_max() == 15000, stuff_we_actually_want))
import matplotlib.pyplot as plt
item = list(filter(lambda x: x.cores == 0 and x.language == "c",table_items))
fig = plt.figure()
ax1 = fig.add_subplot(111)
go_items = list(filter(lambda i: i.cores == 0 and i.language == "go", table_items))
c_items = list(filter(lambda i: i.cores == 0 and i.language == "c", table_items))
go_parallel = list(filter(lambda i: i.cores != 0 and i.language == "go", table_items))
c_parallel = list(filter(lambda i: i.cores != 0 and i.language == "c", table_items))
ax1.set_xlabel('number of cores')
ax1.set_ylabel('time (seconds)')
ax1.scatter(list(map(lambda i: i.cores if i.cores != 0 else 1, go_items)), list(map(lambda i: i.speed, go_items)), s=10, c='r', marker="s", label='Go single threaded from 1..15000')
ax1.scatter(list(map(lambda i: i.cores if i.cores != 0 else 1, c_items)), list(map(lambda i: i.speed, c_items)), s=10, c='g', marker="s", label='C single threaded from 1..15000')
ax1.scatter(list(map(lambda i: i.cores if i.cores != 0 else 1, go_parallel)), list(map(lambda i: i.speed, go_parallel)), s=10, c='b', marker="s", label='Go multithreaded from 1..15000')
ax1.scatter(list(map(lambda i: i.cores if i.cores != 0 else 1, c_parallel)), list(map(lambda i: i.speed, c_parallel)), s=10, c='c', marker="s", label='C multithreaded from 1..15000')
plt.legend(loc='upper right');
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment