Skip to content

Commit 3c41837

Browse files
committed
Add benchmark graph and section to README for cLog performance visualization
1 parent cc70d7b commit 3c41837

3 files changed

Lines changed: 65 additions & 6 deletions

File tree

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616

1717
```cpp
1818
#include "include/logger.hpp"
19-
#include "include/file_sink.hpp"
19+
#include "include/logger_config.hpp"
20+
#include <memory>
2021

2122
int main() {
22-
c_log::Logger log;
23-
log.add_sink(std::make_unique<c_log::FileSink>("log.json"));
24-
log.info("startup").kv("user", "alice").kv("run", 1);
23+
auto log = c_log::logger_from_config("logger.json");
24+
log->info("startup").kv("user", "alice").kv("run", 1);
25+
}
26+
```
27+
28+
// logger.json example:
29+
```
30+
{
31+
"mode": "async", // "sync" or "async"
32+
"level": "info" // "trace", "debug", ...
2533
}
2634
```
2735

@@ -34,12 +42,24 @@ Just add `include/` to your project. No dependencies except C++17 STL and the bu
3442
> [!CAUTION]
3543
> If you're compiling on Windows, make sure your compiler supports at least C++17. See [CI status](https://github.com/mbn-code/cLog/actions) for tested environments.
3644
45+
## Benchmarks
46+
47+
The following graph shows the average time (in microseconds) to log a single entry under different modes and sinks (lower is better):
48+
49+
<p align="center">
50+
<img src="./benchmarks/benchmark.png" alt="cLog benchmarks bar graph" width="500">
51+
</p>
52+
53+
_Benchmark run on a modern Linux machine (100,000 logs per variant, see `benchmarks/benchmark_logger.cpp`)._
54+
55+
---
56+
3757
## Features
3858
- Async and sync modes (`Logger::Mode`)
3959
- Safe, automatic background flushing and shutdown
4060
- Console and file sinks out of the box
4161
- Fully structured JSON logs
42-
- Clean, chainable API: `info().kv().kv()`
62+
- Clean, chainable API: `info().kv().kv()`, now with `debug()`, `warn()`, `error()` and all levels
4363
- Lossless, race-free, and cross-platform
4464

4565
> [!TIP]
@@ -75,7 +95,7 @@ log.add_sink(std::make_unique<MySink>());
7595
- [x] CI/test coverage (Linux/Ubuntu)
7696
- [ ] More flexible external sink/plugin system
7797
- [ ] Windows and Mac CI
78-
- [ ] Simple config file support
98+
- [x] Simple config file support (JSON, see examples/logger.json, logger_config.hpp)
7999

80100
## License
81101
MIT - see [LICENSE](LICENSE)

benchmarks/benchmark.png

27.9 KB
Loading

benchmarks/plot_benchmarks.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
import seaborn as sns
4+
5+
# Read the CSV file
6+
df = pd.read_csv("benchmark_results.csv")
7+
8+
# Remove noop for cleaner graph
9+
plot_df = df[df["logger"] != "noop"]
10+
11+
# Compose readable labels
12+
plot_df["Label"] = (
13+
plot_df["logger"] + " [" + plot_df["sink"] + ", " + plot_df["mode"] + "]"
14+
)
15+
16+
# Sort by performance (ascending)
17+
plot_df = plot_df.sort_values("usec_per_log")
18+
19+
# Set style
20+
sns.set_theme(style="whitegrid")
21+
22+
plt.figure(figsize=(8, 4))
23+
bar = sns.barplot(
24+
data=plot_df,
25+
y="Label",
26+
x="usec_per_log",
27+
palette="Blues_d",
28+
edgecolor="k",
29+
)
30+
plt.xlabel("Time per log entry (μs)")
31+
plt.ylabel("")
32+
plt.title("cLog Benchmark Results (lower is better)")
33+
plt.tight_layout()
34+
35+
for container in bar.containers:
36+
bar.bar_label(container, fmt="%.2f")
37+
38+
plt.savefig("benchmark.png")
39+
print("Graph saved to benchmark.png")

0 commit comments

Comments
 (0)