diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c03c570b..3ebabf25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -212,7 +212,7 @@ jobs: - name: Restore cargo caches uses: Swatinem/rust-cache@v2 - name: Run benchmark - run: cargo +nightly bench --features "multi-thread,runtime-pattern" --bench spdlog_rs --bench spdlog_rs_pattern | tee bench-results.txt + run: cargo +nightly bench --features "multi-thread,runtime-pattern,serde_json" --bench spdlog_rs --bench spdlog_rs_pattern | tee bench-results.txt - name: Discard irrelevant changes run: git checkout -- spdlog/Cargo.toml - name: Process results diff --git a/spdlog/Cargo.toml b/spdlog/Cargo.toml index 9aaffaf0..59012203 100644 --- a/spdlog/Cargo.toml +++ b/spdlog/Cargo.toml @@ -109,6 +109,7 @@ harness = false [[bench]] name = "spdlog_rs_pattern" path = "benches/spdlog-rs/pattern.rs" +required-features = ["runtime-pattern", "serde_json"] [[bench]] name = "fast_log" path = "benches/fast_log/main.rs" diff --git a/spdlog/benches/spdlog-rs/pattern.rs b/spdlog/benches/spdlog-rs/pattern.rs index ea251e15..111dc4f9 100644 --- a/spdlog/benches/spdlog-rs/pattern.rs +++ b/spdlog/benches/spdlog-rs/pattern.rs @@ -5,6 +5,8 @@ extern crate test; use std::{cell::RefCell, sync::Arc}; use paste::paste; +#[cfg(feature = "serde_json")] +use spdlog::formatter::JsonFormatter; use spdlog::{ formatter::{pattern, Formatter, FullFormatter, Pattern, PatternFormatter}, prelude::*, @@ -104,6 +106,12 @@ fn bench_1_full_formatter(bencher: &mut Bencher) { bench_formatter(bencher, FullFormatter::new()) } +#[cfg(feature = "serde_json")] +#[bench] +fn bench_1_json_formatter(bencher: &mut Bencher) { + bench_formatter(bencher, JsonFormatter::new()) +} + #[bench] fn bench_2_full_pattern_ct(bencher: &mut Bencher) { bench_full_pattern( diff --git a/spdlog/src/formatter/json_formatter.rs b/spdlog/src/formatter/json_formatter.rs index 48156a61..346caed5 100644 --- a/spdlog/src/formatter/json_formatter.rs +++ b/spdlog/src/formatter/json_formatter.rs @@ -155,6 +155,10 @@ impl JsonFormatter { let json_record: JsonRecord = record.into(); + // TODO: https://github.com/serde-rs/json/issues/863 + // + // The performance can be significantly optimized here if the issue can be + // solved. dest.write_str(&serde_json::to_string(&json_record)?)?; dest.write_str(__EOL)?;