From 61fabea500607327d5f005f9dfc68ec8e7e8949c Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Tue, 22 Aug 2023 15:25:42 +0200 Subject: [PATCH] added measure_all and graph.py thx @112RG's hyperbench --- .gitignore | 2 ++ flake.nix | 1 + wrk/graph.py | 82 ++++++++++++++++++++++++++++++++++++++++++++++ wrk/measure_all.sh | 9 +++++ 4 files changed, 94 insertions(+) create mode 100644 wrk/graph.py create mode 100755 wrk/measure_all.sh diff --git a/.gitignore b/.gitignore index b7cbd80..6b2dd8e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ scratch docs/ .DS_Store .vs/ +**/*.perflog +wrk/*.png diff --git a/flake.nix b/flake.nix index 2adee62..f278263 100644 --- a/flake.nix +++ b/flake.nix @@ -48,6 +48,7 @@ wrk python39 python39Packages.sanic + python39Packages.matplotlib poetry poetry pkgs.rustc diff --git a/wrk/graph.py b/wrk/graph.py new file mode 100644 index 0000000..617a590 --- /dev/null +++ b/wrk/graph.py @@ -0,0 +1,82 @@ +import re +import os +import matplotlib.pyplot as plt +from matplotlib.ticker import FuncFormatter +from collections import defaultdict +import statistics + +directory = "./" # Replace with the actual directory path + +requests_sec = defaultdict(list) +transfers_sec = defaultdict(list) + +mean_requests = {} +mean_transfers = {} + + +def plot(kind='', title='', ylabel='', means=None): + # Sort the labels and requests_sec lists together based on the requests_sec values + labels = [] + values = [] + + # silly, I know + for k, v in means.items(): + labels.append(k) + values.append(v) + + # sort the labels and value lists + labels, values = zip(*sorted(zip(labels, values), key=lambda x: x[1], reverse=True)) + + # Plot the graph + plt.figure(figsize=(10, 6)) # Adjust the figure size as needed + bars = plt.bar(labels, values) + plt.xlabel("Subject") + plt.ylabel(ylabel) + plt.title(title) + plt.xticks(rotation=45) # Rotate x-axis labels for better readability + + # Display the actual values on top of the bars + for bar in bars: + yval = bar.get_height() + plt.text(bar.get_x() + bar.get_width() / 2, yval, f'{yval:,.2f}', ha='center', va='bottom') + + plt.tight_layout() # Adjust the spacing of the graph elements + plt.savefig(f"{kind.lower()}_graph.png") # Save the graph as a PNG file + + +if __name__ == '__main__': + # Iterate over the files in the directory + for filename in os.listdir(directory): + if filename.endswith(".perflog"): + label = os.path.splitext(filename)[0] + file_path = os.path.join(directory, filename) + + with open(file_path, "r") as file: + lines = file.readlines() + for line in lines: + # Extract the Requests/sec value using regular expressions + match = re.search(r"Requests/sec:\s+([\d.]+)", line) + if match: + requests_sec[label].append(float(match.group(1))) + match = re.search(r"Transfer/sec:\s+([\d.]+)", line) + if match: + value = float(match.group(1)) + if 'KB' in line: + value *= 1024 + elif 'MB' in line: + value *= 1024 * 1024 + value /= 1024.0 * 1024 + transfers_sec[label].append(value) + + # calculate means + for k, v in requests_sec.items(): + mean_requests[k] = statistics.mean(v) + + for k, v in transfers_sec.items(): + mean_transfers[k] = statistics.mean(v) + + # save the plots + plot(kind='req_per_sec', title='Requests/sec Comparison', + ylabel='requests/sec', means=mean_requests) + plot(kind='xfer_per_sec', title='Transfer/sec Comparison', + ylabel='transfer/sec [MB]', means=mean_transfers) diff --git a/wrk/measure_all.sh b/wrk/measure_all.sh new file mode 100755 index 0000000..7a533ba --- /dev/null +++ b/wrk/measure_all.sh @@ -0,0 +1,9 @@ +#! /usr/bin/env bash +SUBJECTS="zig go python sanic rust rust2 axum csharp cpp" + +for S in $SUBJECTS; do + L="$S.perflog" + for R in 1 2 3 ; do + ./wrk/measure.sh $S | tee -a $L + done +done