-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_main.cpp
More file actions
54 lines (50 loc) · 1.68 KB
/
Copy pathbench_main.cpp
File metadata and controls
54 lines (50 loc) · 1.68 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
#include <cstdlib>
#include <iostream>
#include <string>
#include <string_view>
#include "benchmark.h"
// Single-config benchmark runner. Emits ONE CSV row so the sweep script can run
// each thread count in its own process (giving an accurate per-config peak RSS).
//
// log_bench --input <file> --threads N [--chunk-mb 16] [--header]
//
// CSV columns: threads,runtime_ms,throughput_mb_s,peak_rss_mb,total_requests
int main(int argc, char** argv) {
std::string input;
unsigned threads = 1;
std::size_t chunk_mb = 16;
bool header = false;
for (int i = 1; i < argc; ++i) {
std::string_view a = argv[i];
auto next = [&]() -> std::string { return (i + 1 < argc) ? argv[++i] : ""; };
if (a == "--input") {
input = next();
} else if (a == "--threads") {
threads = static_cast<unsigned>(std::stoul(next()));
} else if (a == "--chunk-mb") {
chunk_mb = static_cast<std::size_t>(std::stoul(next()));
} else if (a == "--header") {
header = true;
} else {
std::cerr << "Unknown argument: " << a << "\n";
return 2;
}
}
if (input.empty()) {
std::cerr << "Usage: log_bench --input <file> --threads N "
"[--chunk-mb 16] [--header]\n";
return 2;
}
try {
BenchmarkResult r = run_benchmark(input, threads, chunk_mb * 1024 * 1024);
if (header) {
std::cout << "threads,runtime_ms,throughput_mb_s,peak_rss_mb,total_requests\n";
}
std::cout << r.threads << "," << r.runtime_ms << "," << r.throughput_mb_s << ","
<< r.peak_rss_mb << "," << r.total_requests << "\n";
return 0;
} catch (const std::exception& ex) {
std::cerr << "Error: " << ex.what() << "\n";
return 1;
}
}