Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better plot.py with Python 3 & remove hard code #569

Merged
merged 4 commits into from Oct 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 21 additions & 45 deletions crossbeam-channel/benchmarks/plot.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

import sys
import matplotlib.pyplot as plt
Expand All @@ -17,68 +17,44 @@
def plot(subplot, title, prefix, runs):
runs.reverse()

ys = [6 * (i+1) for i in xrange(len(runs))]
ys = [6 * (i + 1) for i in range(len(runs))]
ax = fig.add_subplot(subplot)
ax.set_title(title)
ax.set_yticks(ys)
ax.set_yticklabels(runs)
ax.tick_params(which='major', length=0)
ax.set_xlabel('seconds')

go = [0] * len(runs)
mpsc = [0] * len(runs)
futures_channel = [0] * len(runs)
chan = [0] * len(runs)
crossbeam_channel = [0] * len(runs)
scores = {}

for (i, run) in enumerate(runs):
for (test, lang, impl, secs) in results:
if test == prefix + '_' + run:
if lang == 'Go' and impl == 'chan':
go[i] = secs
if lang == 'Rust' and impl == 'mpsc':
mpsc[i] = secs
if lang == 'Rust' and impl == 'futures-channel':
futures_channel[i] = secs
if lang == 'Rust' and impl == 'chan':
chan[i] = secs
if lang == 'Rust' and impl == 'crossbeam-channel':
crossbeam_channel[i] = secs
name = lang + '_' + impl
if name not in scores:
scores[name] = [0] * len(runs)
scores[name][i] = secs

opts = dict(height=0.7, align='center')
ax.barh([y-2 for y in ys], go, color='skyblue', **opts)
ax.barh([y-1 for y in ys], crossbeam_channel, color='red', **opts)
ax.barh([y+0 for y in ys], chan, color='orange', **opts)
ax.barh([y+1 for y in ys], mpsc, color='black', **opts)
ax.barh([y+2 for y in ys], futures_channel, color='blue', **opts)
for (i, score) in enumerate(scores.values()):
ax.barh([y + i - len(scores) // 2 for y in ys], score, **opts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're losing the different colors here, perhaps have a fixed colors list that you index with i?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matplotlib will allocate different colors automatically


m = int(max(go + mpsc + futures_channel + chan + crossbeam_channel) * 1.3)
m = int(max(max([x for x in scores.values()])) * 1.3)
if m < 10:
ax.set_xticks(range(m + 1))
ax.set_xticks(list(range(m + 1)))
elif m < 50:
ax.set_xticks([x*5 for x in range(m / 5 + 1)])
ax.set_xticks([x * 5 for x in range(m // 5 + 1)])
elif m < 100:
ax.set_xticks([x*10 for x in range(m / 10 + 1)])
elif m < 100:
ax.set_xticks([x*20 for x in range(m / 20 + 1)])
ax.set_xticks([x * 10 for x in range(m // 10 + 1)])
elif m < 400:
ax.set_xticks([x * 20 for x in range(m // 20 + 1)])
else:
ax.set_xticks([x*100 for x in range(m / 100 + 1)])

for (x, y) in zip(go, ys):
if x > 0:
ax.text(x+m/200., y-2-0.3, 'Go', fontsize=9)
for (x, y) in zip(crossbeam_channel, ys):
if x > 0:
ax.text(x+m/200., y-1-0.3, 'crossbeam-channel', fontsize=9)
for (x, y) in zip(chan, ys):
if x > 0:
ax.text(x+m/200., y+0-0.3, 'chan', fontsize=9)
for (x, y) in zip(mpsc, ys):
if x > 0:
ax.text(x+m/200., y+1-0.3, 'mpsc', fontsize=9)
for (x, y) in zip(futures_channel, ys):
if x > 0:
ax.text(x+m/200., y+2-0.3, 'futures-channel', fontsize=9)
ax.set_xticks([x * 100 for x in range(m // 100 + 1)])

for (i, (name, score)) in enumerate(scores.items()):
for (x, y) in zip(score, ys):
ax.text(x + m / 200., y + i - len(scores) // 2 - 0.25, name, fontsize=9)


plot(
221,
Expand Down