cpu-bench: add clear

This commit is contained in:
Jaewook Lee
2024-08-12 18:50:07 +09:00
parent cc6dfa392f
commit bce6400477

View File

@@ -1,16 +1,26 @@
#!/usr/bin/env python #!/usr/bin/env python
def ensure(*packages):
for pkg in packages:
try: __import__(pkg)
except: import os; os.sytem(f'pip install -q {pkg}')
ensure('pandas', 'tabulate')
import subprocess, multiprocessing as mp, warnings, pandas as pd import subprocess, multiprocessing as mp, warnings, pandas as pd
from tabulate import tabulate from tabulate import tabulate
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0)) R, G, B, W = (f'\x1b[{x}m' for x in (31, 32, 34, 0))
subprocess.run('clear')
subprocess.run('neofetch') subprocess.run('neofetch')
print(f'{G}$ sysbench cpu --cpu-max-prime=20000 --time=1 --threads=$(nproc) run | grep second{W}')
command = lambda core: f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second'
print(f'{G}$ {command("$(nproc)")}{W}')
def speed(core): def speed(core):
output = subprocess.run( output = subprocess.run(
f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second', command(core), shell=True, capture_output=True, text=True
shell=True, capture_output=True, text=True).stdout.split()[-1] ).stdout.split()[-1]
return float(output) return float(output)
df = [] df = []
@@ -18,7 +28,7 @@ for core in range(1, mp.cpu_count()+1):
s = speed(core) s = speed(core)
row = { row = {
'#Threads': core, '#Threads': core,
'Throughput': s, 'Throughput(/s)': s,
'(per-core)': s/core '(per-core)': s/core
} }
df.append(row) df.append(row)