Skip to content

Commit

Permalink
Add ftlog benchmark for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Jun 12, 2024
1 parent 21d01f3 commit 80d36e7
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
18 changes: 14 additions & 4 deletions spdlog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ sloggers = "=2.2.0"
log4rs = "=1.3.0"
fern = "=0.6.2"
flexi_logger = "=0.28.3"
ftlog = "=0.2.14"
tracing = "=0.1.40"
tracing-subscriber = "=0.3.18"
tracing-appender = "=0.2.3"
Expand All @@ -93,25 +94,34 @@ required-features = ["multi-thread"]
[[bench]]
name = "spdlog_rs"
path = "benches/spdlog-rs/spdlog_rs.rs"

[[bench]]
name = "spdlog_rs_compare_with_cpp_spdlog"
path = "benches/spdlog-rs/compare_with_cpp_spdlog.rs"
harness = false

[[bench]]
name = "spdlog_rs_compare_with_cpp_spdlog_async"
path = "benches/spdlog-rs/compare_with_cpp_spdlog_async.rs"
harness = false

[[bench]]
name = "spdlog_rs_pattern"
path = "benches/spdlog-rs/pattern.rs"
[[bench]]
name = "ftlog"
path = "benches/ftlog/main.rs"
harness = false
[[bench]]
name = "ftlog_1_file_async"
path = "benches/ftlog/1_file_async.rs"
[[bench]]
name = "ftlog_2_rotating_daily"
path = "benches/ftlog/2_rotating_daily.rs"
[[bench]]
name = "ftlog_3_level_off"
path = "benches/ftlog/3_level_off.rs"

[[example]]
name = "06_compatible_with_log_crate"
required-features = ["log"]

[[example]]
name = "07_async_pool_sink"
required-features = ["multi-thread"]
26 changes: 26 additions & 0 deletions spdlog/benches/ftlog/1_file_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![feature(test)]

extern crate test;

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

use ftlog::appender::FileAppender;
use log::info;
use test::Bencher;

unavailable_bench!(bench_1_file);

#[bench]
fn bench_2_file_async(bencher: &mut Bencher) {
let path = common::BENCH_LOGS_PATH.join("file_async.log");

let _guard = ftlog::builder()
.root(FileAppender::builder().path(path).build())
.try_init()
.unwrap();

bencher.iter(|| info!(bench_log_message!()))
}

unavailable_bench!(bench_3_rotating_file_size);
27 changes: 27 additions & 0 deletions spdlog/benches/ftlog/2_rotating_daily.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![feature(test)]

extern crate test;

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

use ftlog::appender::{FileAppender, Period};
use log::info;
use test::Bencher;

#[bench]
fn bench_4_rotating_daily(bencher: &mut Bencher) {
let path = common::BENCH_LOGS_PATH.join("rotating_daily.log");

let _guard = ftlog::builder()
.root(
FileAppender::builder()
.path(path)
.rotate(Period::Day)
.build(),
)
.try_init()
.unwrap();

bencher.iter(|| info!(bench_log_message!()))
}
23 changes: 23 additions & 0 deletions spdlog/benches/ftlog/3_level_off.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![feature(test)]

extern crate test;

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

use ftlog::{appender::FileAppender, LevelFilter};
use log::info;
use test::Bencher;

#[bench]
fn bench_5_level_off(bencher: &mut Bencher) {
let path = common::BENCH_LOGS_PATH.join("level_off.log");

let _guard = ftlog::builder()
.root(FileAppender::builder().path(path).build())
.max_log_level(LevelFilter::Off)
.try_init()
.unwrap();

bencher.iter(|| info!(bench_log_message!()))
}
8 changes: 8 additions & 0 deletions spdlog/benches/ftlog/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(test)]

extern crate test;

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

aggregate_bench_main!();

0 comments on commit 80d36e7

Please sign in to comment.