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

27 lines
699 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]
print(output)
return output
except:
print('\n'
'sudo apt-get update && sudo apt-get install -y sysbench'
'\tOR'
'brew install sysbench'
'\n')
raise
df = []
for core in range(1, mp.cpu_count()+1):
s = speed(core)
df.append((core, s, s/core))
df = pd.DataFrame(df)
df.to_csv('bench.csv', index=False)