Files
wiki/debian-cpu-benchmark/bench.py
2024-08-12 17:45:24 +09:00

33 lines
976 B
Python
Executable File

#!/usr/bin/env python
import subprocess, multiprocessing as mp, pandas as pd
def speed(core):
try:
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)
except:
print('\n'
'sudo apt-get update && sudo apt-get install -y sysbench neofetch'
'\tOR'
'brew install sysbench neofetch'
'\n')
raise
subprocess.run('neofetch')
R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0))
df = []
print(f'\t{G}Speed\t\t{B} Speed')
print(f'\t{G}(multicore)\t{B}(per-core)')
for core in range(1, mp.cpu_count()+1):
print(f'{R}Core: {core}', end='')
s = speed(core)
row = (core, s, s/core)
print(f'\t{G}{int(row[1]):^8}\t{B}{int(row[2]):^8}')
df.append(row)
print(W)
df = pd.DataFrame(df)
df.to_csv('bench.csv', index=False)