|
1 | 1 | import re |
| 2 | +import logging |
2 | 3 | import matplotlib.pyplot as plt |
3 | 4 | import numpy as np |
4 | 5 |
|
| 6 | +# Enable detailed tracing. Set to False to disable verbose output. |
| 7 | +DEBUG = True |
| 8 | +logging.basicConfig(level=logging.INFO if DEBUG else logging.WARNING, |
| 9 | + format="%(message)s") |
| 10 | + |
5 | 11 | data = open('out.txt').read() |
| 12 | +if DEBUG: |
| 13 | + logging.info("Loaded out.txt, length: %d characters", len(data)) |
6 | 14 |
|
7 | 15 | patterns = [ |
8 | 16 | r"BM_(PSQL)/\w+\/?\w+?/(\w+)/\d+/min_warmup_time:20\.000\s+(\d+)\sns\s+\d+\sns\s+\d+", |
|
18 | 26 |
|
19 | 27 | for pattern in patterns: |
20 | 28 | matches = re.findall(pattern, data) |
| 29 | + if DEBUG: |
| 30 | + logging.info("Pattern %s matched %d entries", pattern, len(matches)) |
21 | 31 | for match in matches: |
22 | 32 | if match[0] == 'PSQL': |
23 | 33 | _category, transaction, time = match |
| 34 | + if DEBUG: |
| 35 | + logging.info("PSQL - %s: %s ns", transaction, time) |
24 | 36 | if transaction == "Transaction": |
25 | 37 | PSQL_Transaction.append(int(time)) |
26 | 38 | else: |
27 | 39 | PSQL_NonTransaction.append(int(time)) |
28 | 40 | else: |
29 | 41 | _category, trees, storage, time = match |
| 42 | + if DEBUG: |
| 43 | + logging.info("Doublets %s %s: %s ns", trees, storage, time) |
30 | 44 | if trees == 'United': |
31 | 45 | if storage == 'Volatile': |
32 | 46 | Doublets_United_Volatile.append(int(time)) |
|
38 | 52 | else: |
39 | 53 | Doublets_Split_NonVolatile.append(int(time)) |
40 | 54 |
|
| 55 | +if DEBUG: |
| 56 | + logging.info("\nFinal lists (after parsing):") |
| 57 | + logging.info("PSQL_Transaction: %s", PSQL_Transaction) |
| 58 | + logging.info("PSQL_NonTransaction: %s", PSQL_NonTransaction) |
| 59 | + logging.info("Doublets_United_Volatile: %s", Doublets_United_Volatile) |
| 60 | + logging.info("Doublets_United_NonVolatile: %s", Doublets_United_NonVolatile) |
| 61 | + logging.info("Doublets_Split_Volatile: %s", Doublets_Split_Volatile) |
| 62 | + logging.info("Doublets_Split_NonVolatile: %s", Doublets_Split_NonVolatile) |
| 63 | + |
41 | 64 | labels = ['Create', 'Delete', 'Each Identity', 'Each Concrete', 'Each Outgoing', 'Each Incoming', 'Each All', 'Update'] |
| 65 | + |
| 66 | +# ───────────────────────────────────────────────────────────────────────────── |
| 67 | +# Plots |
| 68 | +# ───────────────────────────────────────────────────────────────────────────── |
| 69 | +def ensure_min_visible(arr, min_val): |
| 70 | + """Ensure non-zero values are at least min_val for visibility on graph.""" |
| 71 | + return [max(v, min_val) if v > 0 else 0 for v in arr] |
| 72 | + |
42 | 73 | def bench1(): |
43 | | - Doublets_United_Volatile_Pixels = [max(1, x // 10000000) for x in Doublets_United_Volatile] |
44 | | - Doublets_United_NonVolatile_Pixels = [max(1, x // 10000000) for x in Doublets_United_NonVolatile] |
45 | | - Doublets_Split_Volatile_Pixels = [max(1, x // 10000000) for x in Doublets_Split_Volatile] |
46 | | - Doublets_Split_NonVolatile_Pixels = [max(1, x // 10000000) for x in Doublets_Split_NonVolatile] |
47 | | - PSQL_NonTransaction_Pixels = [max(1, x // 10000000) for x in PSQL_NonTransaction] |
48 | | - PSQL_Transaction_Pixels = [max(1, x // 10000000) for x in PSQL_Transaction] |
49 | | - |
| 74 | + """Horizontal bars – raw values (pixel scale).""" |
50 | 75 | y = np.arange(len(labels)) |
51 | | - |
52 | 76 | width = 0.1 |
53 | | - |
54 | 77 | fig, ax = plt.subplots(figsize=(12, 8)) |
55 | 78 |
|
56 | | - |
57 | | - rects1 = ax.barh(y - 2*width, Doublets_United_Volatile_Pixels, width, label='Doublets United Volatile', color='salmon') |
58 | | - rects2 = ax.barh(y - width, Doublets_United_NonVolatile_Pixels, width, label='Doublets United NonVolatile', color='red') |
59 | | - |
60 | | - rects3 = ax.barh(y, Doublets_Split_Volatile_Pixels, width, label='Doublets Split Volatile', color='lightgreen') |
61 | | - rects4 = ax.barh(y + width, Doublets_Split_NonVolatile_Pixels, width, label='Doublets Split NonVolatile', color='green') |
62 | | - |
63 | | - rects5 = ax.barh(y + 2*width, PSQL_NonTransaction_Pixels, width, label='PSQL NonTransaction', color='lightblue') |
64 | | - rects6 = ax.barh(y + 3*width, PSQL_Transaction_Pixels, width, label='PSQL Transaction', color='blue') |
65 | | - |
66 | | - ax.set_xlabel('Time (ns) - Scaled to Pixels') |
67 | | - ax.set_title('Benchmark comparison for Doublets and PostgreSQL') |
| 79 | + # Calculate maximum value across all data series to determine scale |
| 80 | + all_values = (Doublets_United_Volatile + Doublets_United_NonVolatile + |
| 81 | + Doublets_Split_Volatile + Doublets_Split_NonVolatile + |
| 82 | + PSQL_NonTransaction + PSQL_Transaction) |
| 83 | + max_val = max(all_values) if all_values else 1 |
| 84 | + |
| 85 | + # Minimum visible bar width: ~0.5% of max value ensures at least 2 pixels |
| 86 | + # on typical 12-inch wide figure at 100 DPI (~900px plot area) |
| 87 | + min_visible = max_val * 0.005 |
| 88 | + if DEBUG: |
| 89 | + logging.info("bench1: max_val=%d, min_visible=%d", max_val, min_visible) |
| 90 | + |
| 91 | + # Apply minimum visibility to all data series |
| 92 | + du_volatile_vis = ensure_min_visible(Doublets_United_Volatile, min_visible) |
| 93 | + du_nonvolatile_vis = ensure_min_visible(Doublets_United_NonVolatile, min_visible) |
| 94 | + ds_volatile_vis = ensure_min_visible(Doublets_Split_Volatile, min_visible) |
| 95 | + ds_nonvolatile_vis = ensure_min_visible(Doublets_Split_NonVolatile, min_visible) |
| 96 | + psql_non_vis = ensure_min_visible(PSQL_NonTransaction, min_visible) |
| 97 | + psql_trans_vis = ensure_min_visible(PSQL_Transaction, min_visible) |
| 98 | + |
| 99 | + ax.barh(y - 2*width, du_volatile_vis, width, label='Doublets United Volatile', color='salmon') |
| 100 | + ax.barh(y - width, du_nonvolatile_vis, width, label='Doublets United NonVolatile', color='red') |
| 101 | + ax.barh(y, ds_volatile_vis, width, label='Doublets Split Volatile', color='lightgreen') |
| 102 | + ax.barh(y + width, ds_nonvolatile_vis, width, label='Doublets Split NonVolatile', color='green') |
| 103 | + ax.barh(y + 2*width, psql_non_vis, width, label='PSQL NonTransaction', color='lightblue') |
| 104 | + ax.barh(y + 3*width, psql_trans_vis, width, label='PSQL Transaction', color='blue') |
| 105 | + |
| 106 | + ax.set_xlabel('Time (ns)') |
| 107 | + ax.set_title('Benchmark Comparison: PostgreSQL vs Doublets (C++)') |
68 | 108 | ax.set_yticks(y) |
69 | 109 | ax.set_yticklabels(labels) |
70 | 110 | ax.legend() |
71 | 111 |
|
72 | 112 | fig.tight_layout() |
73 | | - |
74 | | - plt.savefig("Bench1.png") |
| 113 | + plt.savefig("bench_cpp.png") |
75 | 114 | plt.close(fig) |
| 115 | + if DEBUG: logging.info("bench_cpp.png saved.") |
76 | 116 |
|
77 | 117 | def bench2(): |
| 118 | + """Horizontal bars – raw values on a log scale.""" |
78 | 119 | y = np.arange(len(labels)) |
79 | | - |
80 | 120 | width = 0.1 |
81 | 121 | fig, ax = plt.subplots(figsize=(12, 8)) |
82 | 122 |
|
83 | | - rects1 = ax.barh(y - 2*width, Doublets_United_Volatile, width, label='Doublets United Volatile', color='salmon') |
84 | | - rects2 = ax.barh(y - width, Doublets_United_NonVolatile, width, label='Doublets United NonVolatile', color='red') |
| 123 | + ax.barh(y - 2*width, Doublets_United_Volatile, width, label='Doublets United Volatile', color='salmon') |
| 124 | + ax.barh(y - width, Doublets_United_NonVolatile, width, label='Doublets United NonVolatile', color='red') |
| 125 | + ax.barh(y, Doublets_Split_Volatile, width, label='Doublets Split Volatile', color='lightgreen') |
| 126 | + ax.barh(y + width, Doublets_Split_NonVolatile, width, label='Doublets Split NonVolatile', color='green') |
| 127 | + ax.barh(y + 2*width, PSQL_NonTransaction, width, label='PSQL NonTransaction', color='lightblue') |
| 128 | + ax.barh(y + 3*width, PSQL_Transaction, width, label='PSQL Transaction', color='blue') |
85 | 129 |
|
86 | | - rects3 = ax.barh(y, Doublets_Split_Volatile, width, label='Doublets Split Volatile', color='lightgreen') |
87 | | - rects4 = ax.barh(y + width, Doublets_Split_NonVolatile, width, label='Doublets Split NonVolatile', color='green') |
88 | | - |
89 | | - rects5 = ax.barh(y + 2*width, PSQL_NonTransaction, width, label='PSQL NonTransaction', color='lightblue') |
90 | | - rects6 = ax.barh(y + 3*width, PSQL_Transaction, width, label='PSQL Transaction', color='blue') |
91 | | - |
92 | | - ax.set_xlabel('Time (ns) - Logarithmic Scale') |
93 | | - ax.set_title('Benchmark comparison for Doublets and PostgreSQL') |
| 130 | + ax.set_xlabel('Time (ns) – log scale') |
| 131 | + ax.set_title('Benchmark Comparison: PostgreSQL vs Doublets (C++)') |
94 | 132 | ax.set_yticks(y) |
95 | 133 | ax.set_yticklabels(labels) |
96 | 134 | ax.legend() |
97 | | - |
98 | 135 | ax.set_xscale('log') |
99 | 136 |
|
100 | 137 | fig.tight_layout() |
101 | | - |
102 | | - plt.savefig("Bench2.png") |
| 138 | + plt.savefig("bench_cpp_log_scale.png") |
103 | 139 | plt.close(fig) |
| 140 | + if DEBUG: logging.info("bench_cpp_log_scale.png saved.") |
104 | 141 |
|
105 | 142 | bench1() |
106 | 143 | bench2() |
0 commit comments