in progress

This commit is contained in:
Jaewook Lee
2024-09-01 14:47:58 +09:00
parent a5c579b67b
commit 016e225c74

View File

@@ -1,43 +1,43 @@
#!/usr/bin/env python #!/usr/bin/env python
def ensure(*packages): def ensure(*packages):
for pkg in packages: for pkg in packages:
try: __import__(pkg) try: __import__(pkg)
except: import os; os.system(f'pip install -q {pkg}') except: import os; os.system(f'pip install -q {pkg}')
ensure('pandas', 'tabulate') ensure('pandas', 'tabulate')
import subprocess, multiprocessing as mp, warnings, pandas as pd import subprocess, multiprocessing as mp, warnings, pandas as pd
from tqdm.auto import tqdm from tqdm.auto import tqdm
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('clear')
subprocess.run('neofetch') subprocess.run('neofetch')
command = lambda core: f'sysbench cpu --cpu-max-prime=20000 --time=1 --threads={core} run | grep second' 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) print(f'{G}$ {command("$(nproc)")}{W}', flush=True)
def speed(core): def speed(core):
output = subprocess.run( output = subprocess.run(
command(core), shell=True, capture_output=True, text=True command(core), shell=True, capture_output=True, text=True
).stdout.split()[-1] ).stdout.split()[-1]
return float(output) return float(output)
df = [] df = []
for core in range(1, mp.cpu_count()+1): for core in range(1, mp.cpu_count()+1):
s = speed(core) s = speed(core)
row = { row = {
'#Threads': core, '#Threads': core,
'Throughput(/s)': s, 'Throughput(/s)': s,
'(per-core)': s/core '(per-core)': s/core
} }
df.append(row) df.append(row)
df = pd.DataFrame(df) df = pd.DataFrame(df)
df.to_csv('result.csv', index=False) df.to_csv('result.csv', index=False)
df.iloc[:, 0] = df.iloc[:, 0].apply(lambda s: f'{R}{s}{W}') 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[:, 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}') df.iloc[:, 2] = df.iloc[:, 2].apply(lambda s: f'{B}{int(s)}{W}')
print(tabulate(df, headers='keys', tablefmt='rounded_outline', showindex=False)) print(tabulate(df, headers='keys', tablefmt='rounded_outline', showindex=False))