-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathroles.MD
More file actions
126 lines (103 loc) · 3.33 KB
/
Copy pathroles.MD
File metadata and controls
126 lines (103 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
Cache benchmark runner for portfolio query caching.
Runs the ignored Rust benchmark-style test and extracts:
- get_portfolio cold vs warm average latency
- get_top_traders cold vs warm average latency
- cache hit/miss counters and hit ratio
Usage:
python3 scripts/benchmark_cache.py
"""
import re
import shutil
import subprocess
import sys
BENCH_CMD = [
"cargo",
"test",
"-p",
"counter",
"benchmark_cache_latency_and_hit_ratio",
"--release",
"--",
"--ignored",
"--nocapture",
]
LINE_PATTERN = re.compile(
r"CACHE_BENCH\s+"
r"portf_cold_ms=(?P<portf_cold>[0-9.]+)\s+"
r"portf_warm_ms=(?P<portf_warm>[0-9.]+)\s+"
r"portf_delta_pct=(?P<portf_delta>-?[0-9.]+)\s+"
r"top_cold_ms=(?P<top_cold>[0-9.]+)\s+"
r"top_warm_ms=(?P<top_warm>[0-9.]+)\s+"
r"top_delta_pct=(?P<top_delta>-?[0-9.]+)\s+"
r"hits=(?P<hits>[0-9]+)\s+"
r"misses=(?P<misses>[0-9]+)\s+"
r"hit_ratio_pct=(?P<hit_ratio>[0-9.]+)"
)
def _print_setup_hint() -> None:
print("cargo is not installed or not on PATH.")
print("Install Rust toolchain and retry:")
print(" curl https://sh.rustup.rs -sSf | sh")
print(" source $HOME/.cargo/env")
def _evaluate_target(delta_pct: float) -> str:
if 30.0 <= delta_pct <= 50.0:
return "PASS"
return "WARN"
def main() -> int:
if shutil.which("cargo") is None:
_print_setup_hint()
return 2
print("Running cache benchmark test...")
proc = subprocess.run(BENCH_CMD, capture_output=True, text=True)
output = proc.stdout + "\n" + proc.stderr
if proc.returncode != 0:
print("Benchmark command failed.")
print(output)
return proc.returncode
match = LINE_PATTERN.search(output)
if not match:
print("Could not find CACHE_BENCH output line.")
print(output)
return 3
portf_cold = float(match.group("portf_cold"))
portf_warm = float(match.group("portf_warm"))
portf_delta = float(match.group("portf_delta"))
top_cold = float(match.group("top_cold"))
top_warm = float(match.group("top_warm"))
top_delta = float(match.group("top_delta"))
hits = int(match.group("hits"))
misses = int(match.group("misses"))
hit_ratio = float(match.group("hit_ratio"))
print("Cache benchmark summary")
print(f" get_portfolio cold avg: {portf_cold:.6f} ms")
print(f" get_portfolio warm avg: {portf_warm:.6f} ms")
print(f" get_portfolio reduction: {portf_delta:.2f}% [{_evaluate_target(portf_delta)}]")
print(f" get_top_traders cold avg: {top_cold:.6f} ms")
print(f" get_top_traders warm avg: {top_warm:.6f} ms")
print(f" get_top_traders reduction: {top_delta:.2f}% [{_evaluate_target(top_delta)}]")
print(f" cache hits: {hits}")
print(f" cache misses: {misses}")
print(f" cache hit ratio: {hit_ratio:.2f}%")
return 0
if __name__ == "__main__":
sys.exit(main())
use std::time::Instant;
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use serde_json::Value;
mod performance_benchmark;
use performance_benchmark::{run_benchmarks, BenchmarkRunner, BenchmarkResult};
/// Configuration for the benchmark runner
struct BenchmarkConfig {
iterations: usize,
warmup_runs: usize,
output_format: OutputFormat,
}
#[derive(Debug)]
enum OutputFormat {
Console,
Json,
Csv,
}