Skip to content

Commit

Permalink
Add benchmark for KV
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Feb 13, 2025
1 parent b517657 commit 9339cf8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spdlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ name = "spdlog_rs_pattern"
path = "benches/spdlog-rs/pattern.rs"
required-features = ["runtime-pattern", "serde_json"]
[[bench]]
name = "spdlog_rs_kv"
path = "benches/spdlog-rs/kv.rs"
[[bench]]
name = "fast_log"
path = "benches/fast_log/main.rs"
harness = false
Expand Down
56 changes: 56 additions & 0 deletions spdlog/benches/spdlog-rs/kv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#![feature(test)]

extern crate test;

#[path = "../common/mod.rs"]
mod common;

use std::sync::Arc;

use spdlog::{prelude::*, sink::*};
use test::Bencher;

include!(concat!(
env!("OUT_DIR"),
"/test_utils/common_for_integration_test.rs"
));
use test_utils::*;

fn logger(name: &str) -> Logger {
let path = common::BENCH_LOGS_PATH.join(format!("kv_{name}.log"));
let sink = Arc::new(
FileSink::builder()
.path(path)
.truncate(true)
.build()
.unwrap(),
);
build_test_logger(|b| b.sink(sink))
}

#[bench]
fn bench_kv_str(bencher: &mut Bencher) {
let logger = logger("str");
bencher.iter(
|| info!(logger: logger, bench_log_message!(), kv: { k1 = "v1", k2 = "v2", k3 = "v3" }),
)
}

#[bench]
fn bench_kv_mixed(bencher: &mut Bencher) {
let logger = logger("mixed");
let v = vec![1];
bencher.iter(|| info!(logger: logger, bench_log_message!(), kv: { k1 = 1, k2: = 1.0, v:? }))
}

#[bench]
fn bench_kv_many(bencher: &mut Bencher) {
let logger = logger("12_kv");
bencher.iter(|| {
info!(logger: logger, bench_log_message!(), kv: {
k1 = "v1", k2 = "v2", k3 = "v3", k4 = "v4",
k5 = "v5", k6 = "v6", k7 = "v7", k8 = "v8",
k9 = "v9", k10 = "v10", k11 = "v11", k12 = "v12",
})
})
}

0 comments on commit 9339cf8

Please sign in to comment.