From 016e225c74f68ab797b1f88a1b1e643584feeaf1 Mon Sep 17 00:00:00 2001 From: Jaewook Lee <11328376+jaewooklee93@users.noreply.github.com> Date: Sun, 1 Sep 2024 14:47:58 +0900 Subject: [PATCH] in progress --- cpu-bench/bench.py | 86 +++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/cpu-bench/bench.py b/cpu-bench/bench.py index 8ffa1fd..43be1b3 100644 --- a/cpu-bench/bench.py +++ b/cpu-bench/bench.py @@ -1,43 +1,43 @@ -#!/usr/bin/env python - -def ensure(*packages): - for pkg in packages: - try: __import__(pkg) - except: import os; os.system(f'pip install -q {pkg}') -ensure('pandas', 'tabulate') - -import subprocess, multiprocessing as mp, warnings, pandas as pd -from tqdm.auto import tqdm -from tabulate import tabulate -warnings.filterwarnings("ignore") -R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) -subprocess.run('clear') -subprocess.run('neofetch') - -command = lambda core: f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second' - -print(f'{G}$ {command("$(nproc)")}{W}', flush=True) - - -def speed(core): - output = subprocess.run( - command(core), shell=True, capture_output=True, text=True - ).stdout.split()[-1] - return float(output) - -df = [] -for core in range(1, mp.cpu_count()+1): - s = speed(core) - row = { - '#Threads': core, - 'Throughput(/s)': s, - '(per-core)': s/core - } - df.append(row) -df = pd.DataFrame(df) -df.to_csv('result.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)) +#!/usr/bin/env python + +def ensure(*packages): + for pkg in packages: + try: __import__(pkg) + except: import os; os.system(f'pip install -q {pkg}') +ensure('pandas', 'tabulate') + +import subprocess, multiprocessing as mp, warnings, pandas as pd +from tqdm.auto import tqdm +from tabulate import tabulate +warnings.filterwarnings("ignore") +R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) +subprocess.run('clear') +subprocess.run('neofetch') + +command = lambda core: f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second' + +print(f'{G}$ {command("$(nproc)")}{W}', flush=True) + + +def speed(core): + output = subprocess.run( + command(core), shell=True, capture_output=True, text=True + ).stdout.split()[-1] + return float(output) + +df = [] +for core in range(1, mp.cpu_count()+1): + s = speed(core) + row = { + '#Threads': core, + 'Throughput(/s)': s, + '(per-core)': s/core + } + df.append(row) +df = pd.DataFrame(df) +df.to_csv('result.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))