Skip to content

Commit

Permalink
Grouped bar chart graph
Browse files Browse the repository at this point in the history
  • Loading branch information
marxin committed Aug 5, 2024
1 parent 3b4d85f commit de040f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Binary file modified benchmark-time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 25 additions & 13 deletions scripts/benchmark-plot.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse
import glob
import json
import matplotlib.pyplot as plt
import sys
import statistics
import numpy as np

parser = argparse.ArgumentParser()
parser.add_argument(
"-o", "--output", help="Save image to the given filename."
)
parser.add_argument("-o", "--output", help="Save image to the given filename.")

args = parser.parse_args()

commands = None
data = []
inputs = []

for filename in glob.glob("scripts/tmp/benchmark-*.json"):
for filename in sorted(glob.glob("scripts/tmp/benchmark-*.json")):
with open(filename) as f:
results = json.load(f)["results"]
commands = [b["command"] for b in results]
data.append([b["mean"] for b in results])
if not commands:
# initialize the dictionary if empty
commands = {b["command"]: [] for b in results}
for result in results:
commands[result["command"]].append(
statistics.mean([result["mean"] for b in results])
)
inputs.append(results[0]["parameters"]["input"])

data = map(list, zip(*data))
for (times, command) in zip(data, commands):
plt.plot(inputs, times, label=command)
x = np.arange(len(inputs)) # the label locations
width = 0.2 # the width of the bars
multiplier = 0

fig, ax = plt.subplots(layout="constrained")

for command, times in commands.items():
offset = width * multiplier
rects = ax.bar(x + offset, times, width, label=command)
multiplier += 1

ax.set_xticks(x + width, inputs)
ax.legend(title="Tool")

plt.title("addr2line runtime")
plt.xlabel("Input")
plt.ylabel("Time [s]")
plt.ylim(0, None)
plt.legend(title="Tool")

if args.output:
plt.savefig(args.output)
Expand Down

0 comments on commit de040f7

Please sign in to comment.