update test cases 2
This commit is contained in:
+45
-33
@@ -12,52 +12,64 @@ def run_test(n, threads, threshold):
|
|||||||
_, err = process.communicate()
|
_, err = process.communicate()
|
||||||
for line in err.split("\n"):
|
for line in err.split("\n"):
|
||||||
if "STAT:" in line:
|
if "STAT:" in line:
|
||||||
return float(line.split("time=")[1])
|
try:
|
||||||
return 0
|
# 1. Берем часть после "time=" -> "0.010061 sec"
|
||||||
|
# 2. .split() разбивает по пробелу на ["0.010061", "sec"]
|
||||||
|
# 3. [0] берет первый элемент -> "0.010061"
|
||||||
|
time_value = line.split("time=")[1].split()[0]
|
||||||
|
return float(time_value)
|
||||||
|
except (IndexError, ValueError):
|
||||||
|
continue
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
|
||||||
def build_benchmark():
|
def build_benchmark():
|
||||||
n_size = 500000
|
data_sizes = {
|
||||||
|
"Small (10^5)": 100000,
|
||||||
|
"Medium (2*10^6)": 2000000,
|
||||||
|
"Large (5*10^6)": 5000000,
|
||||||
|
}
|
||||||
|
|
||||||
threshold = 10000
|
threshold = 10000
|
||||||
thread_counts = [0, 1, 2, 4, 8, 12, 16]
|
thread_counts = [1, 2, 4, 8, 12, 16]
|
||||||
times = []
|
|
||||||
|
|
||||||
print(f"Запуск бенчмарка (N={n_size}, Порог={threshold})...")
|
plt.figure(figsize=(14, 6))
|
||||||
for t in thread_counts:
|
ax1 = plt.subplot(1, 2, 1)
|
||||||
t_exec = run_test(n_size, t, threshold)
|
ax2 = plt.subplot(1, 2, 2)
|
||||||
times.append(t_exec)
|
|
||||||
print(f"Потоков: {t} | Время: {t_exec:.4f}с")
|
|
||||||
|
|
||||||
plt.figure(figsize=(12, 5))
|
for label, n_size in data_sizes.items():
|
||||||
|
times = []
|
||||||
|
print(f"\nТестирование: {label}...")
|
||||||
|
for t in thread_counts:
|
||||||
|
t_exec = run_test(n_size, t, threshold)
|
||||||
|
times.append(t_exec)
|
||||||
|
print(f" Потоков: {t} | Время: {t_exec:.4f}с")
|
||||||
|
|
||||||
plt.subplot(1, 2, 1)
|
ax1.plot(thread_counts, times, "o-", label=label)
|
||||||
plt.plot(thread_counts, times, "o-", color="blue", label="Фактическое время")
|
t_seq = times[0]
|
||||||
plt.xlabel("Потоки")
|
speedup = [t_seq / x if x > 0 else 1 for x in times]
|
||||||
plt.ylabel("Время (сек)")
|
ax2.plot(thread_counts, speedup, "s-", label=label)
|
||||||
plt.title("Время выполнения")
|
|
||||||
plt.grid(True)
|
|
||||||
|
|
||||||
plt.subplot(1, 2, 2)
|
ax1.set_xlabel("Потоки")
|
||||||
t_seq = times[0]
|
ax1.set_ylabel("Время (сек)")
|
||||||
speedup = [t_seq / x if x > 0 else 1 for x in times]
|
ax1.set_title("Время выполнения")
|
||||||
plt.plot(thread_counts, speedup, "s-", color="green", label="Ускорение")
|
ax1.legend()
|
||||||
plt.plot(
|
ax1.grid(True)
|
||||||
thread_counts,
|
|
||||||
[x if x > 0 else 1 for x in thread_counts],
|
ax2.plot(
|
||||||
"--",
|
thread_counts, thread_counts, "--", color="black", alpha=0.3, label="Идеал"
|
||||||
color="red",
|
|
||||||
alpha=0.5,
|
|
||||||
)
|
)
|
||||||
plt.xlabel("Потоки")
|
ax2.set_xlabel("Потоки")
|
||||||
plt.ylabel("Ускорение S")
|
ax2.set_ylabel("Ускорение")
|
||||||
plt.title("Масштабируемость")
|
ax2.set_title("Масштабируемость")
|
||||||
plt.grid(True)
|
ax2.legend()
|
||||||
|
ax2.grid(True)
|
||||||
|
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
|
os.makedirs("out", exist_ok=True)
|
||||||
plt.savefig("out/performance_results.png")
|
plt.savefig("out/performance_results.png")
|
||||||
|
print("\nГрафик производительности сохранен в out/performance_results.png")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if not os.path.exists("out"):
|
|
||||||
os.makedirs("out")
|
|
||||||
build_benchmark()
|
build_benchmark()
|
||||||
|
|||||||
Reference in New Issue
Block a user