Skip to content

Commit

Permalink
Add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Aug 5, 2024
1 parent 18edfe4 commit e698a45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spdlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions spdlog/benches/spdlog-rs/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions spdlog/src/formatter/json_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit e698a45

Please sign in to comment.