diff --git a/Cargo.toml b/Cargo.toml index 2761ae335..1ca5a435a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,6 +78,7 @@ path = "fish-rust/src/lib.rs" # These tests are run by fish_tests(). default = ["fish-ffi-tests"] fish-ffi-tests = ["inventory"] +benchmark = [] # The following features are auto-detected by the build-script and should not be enabled manually. asan = [] diff --git a/fish-rust/src/lib.rs b/fish-rust/src/lib.rs index 0b4e3293f..d003f32f1 100644 --- a/fish-rust/src/lib.rs +++ b/fish-rust/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(feature = "benchmark", feature(test))] #![allow(non_camel_case_types)] #![allow(dead_code)] #![allow(non_upper_case_globals)] diff --git a/fish-rust/src/tests/encoding.rs b/fish-rust/src/tests/encoding.rs index 34fa458d5..09d9ca349 100644 --- a/fish-rust/src/tests/encoding.rs +++ b/fish-rust/src/tests/encoding.rs @@ -17,3 +17,17 @@ fn test_convert_nulls() { let out_wstr = str2wcstring(&out_str); assert_eq!(input, &out_wstr); } + +#[cfg(feature = "benchmark")] +mod bench { + extern crate test; + use crate::tests::encoding::str2wcstring; + use test::Bencher; + + #[bench] + fn bench_convert_ascii(b: &mut Bencher) { + let s: [u8; 128 * 1024] = std::array::from_fn(|i| b'0' + u8::try_from(i % 10).unwrap()); + b.bytes = u64::try_from(s.len()).unwrap(); + b.iter(|| str2wcstring(&s)); + } +} diff --git a/fish-rust/src/tests/mod.rs b/fish-rust/src/tests/mod.rs index 315b8d234..dba612ccd 100644 --- a/fish-rust/src/tests/mod.rs +++ b/fish-rust/src/tests/mod.rs @@ -6,6 +6,7 @@ mod debounce; #[cfg(test)] mod editable_line; +#[cfg(test)] mod encoding; mod env; mod env_universal_common; diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 265e99e06..b46d4c253 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -408,24 +408,6 @@ static void test_convert_private_use() { } } -// todo!("port this"); -static void perf_convert_ascii() { - std::string s(128 * 1024, '\0'); - for (size_t i = 0; i < s.size(); i++) { - s[i] = (i % 10) + '0'; - } - (void)str2wcstring(s); - - double start = timef(); - const int iters = 1024; - for (int i = 0; i < iters; i++) { - (void)str2wcstring(s); - } - double end = timef(); - auto usec = static_cast(((end - start) * 1E6) / iters); - say(L"ASCII string conversion perf: %lu bytes in %llu usec", s.size(), usec); -} - // todo!("already ported, delete this"); static void test_iothread() { say(L"Testing iothreads"); @@ -1203,7 +1185,6 @@ static const test_t s_tests[]{ {TEST_GROUP("convert"), test_convert}, {TEST_GROUP("convert"), test_convert_private_use}, {TEST_GROUP("convert_ascii"), test_convert_ascii}, - {TEST_GROUP("perf_convert_ascii"), perf_convert_ascii, true}, {TEST_GROUP("iothread"), test_iothread}, {TEST_GROUP("pthread"), test_pthread}, {TEST_GROUP("lru"), test_lru},