From 710be724280ff2681ebe9d9e0df57eb1186cd7c8 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:18:45 +0900 Subject: [PATCH] cpu-bench: change dir --- cpu-bench/.gitignore | 1 + cpu-bench/bench.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cpu-bench/.gitignore create mode 100755 cpu-bench/bench.py diff --git a/cpu-bench/.gitignore b/cpu-bench/.gitignore new file mode 100644 index 0000000..df68529 --- /dev/null +++ b/cpu-bench/.gitignore @@ -0,0 +1 @@ +bench.csv diff --git a/cpu-bench/bench.py b/cpu-bench/bench.py new file mode 100755 index 0000000..31968c2 --- /dev/null +++ b/cpu-bench/bench.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import subprocess, multiprocessing as mp, warnings, pandas as pd +from tabulate import tabulate +warnings.filterwarnings("ignore") +R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) +subprocess.run('neofetch') + +def speed(core): + output = subprocess.run( + f'sysbench cpu --threads={core} run | grep "events per second"', + shell=True, capture_output=True, text=True).stdout.split()[-1] + return float(output) + +df = [] +for core in range(1, mp.cpu_count()+2): + s = speed(core) + row = { + '#Threads': core, + 'Throughput': s, + '(per-core)': s/core + } + df.append(row) +df = pd.DataFrame(df) +df.to_csv('bench.csv', index=False) + +df.iloc[:, 0] = df.iloc[:, 0].apply(lambda s: f'{R}{s}{W}') +df.iloc[:, 1] = df.iloc[:, 1].apply(lambda s: f'{G}{int(s)}{W}') +df.iloc[:, 2] = df.iloc[:, 2].apply(lambda s: f'{B}{int(s)}{W}') +print(tabulate(df, headers='keys', tablefmt='rounded_outline', showindex=False))