cpu-benchmark: add tabulate
This commit is contained in:
@@ -1,32 +1,30 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import subprocess, multiprocessing as mp, pandas as pd
|
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):
|
def speed(core):
|
||||||
try:
|
|
||||||
output = subprocess.run(
|
output = subprocess.run(
|
||||||
f'sysbench cpu --threads={core} run | grep "events per second"',
|
f'sysbench cpu --threads={core} run | grep "events per second"',
|
||||||
shell=True, capture_output=True, text=True).stdout.split()[-1]
|
shell=True, capture_output=True, text=True).stdout.split()[-1]
|
||||||
return float(output)
|
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 = []
|
df = []
|
||||||
print(f'\t{G}Speed\t\t{B} Speed')
|
for core in range(1, mp.cpu_count()+2):
|
||||||
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)
|
s = speed(core)
|
||||||
row = (core, s, s/core)
|
row = {
|
||||||
print(f'\t{G}{int(row[1]):^8}\t{B}{int(row[2]):^8}')
|
'#Threads': core,
|
||||||
|
'Throughput': s,
|
||||||
|
'(per-core)': s/core
|
||||||
|
}
|
||||||
df.append(row)
|
df.append(row)
|
||||||
print(W)
|
|
||||||
df = pd.DataFrame(df)
|
df = pd.DataFrame(df)
|
||||||
df.to_csv('bench.csv', index=False)
|
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))
|
||||||
Reference in New Issue
Block a user