-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from varphone/develop
Introduced the `minify_key` feature for `i18n!` and added support for format specifiers in `t!`
- Loading branch information
Showing
33 changed files
with
2,447 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rust_i18n::t; | ||
|
||
rust_i18n::i18n!("./tests/locales", minify_key = true, minify_key_len = 12); | ||
|
||
pub fn bench_t(c: &mut Criterion) { | ||
c.bench_function("t", |b| b.iter(|| t!("hello"))); | ||
|
||
c.bench_function("t_lorem_ipsum", |b| b.iter(|| t!( | ||
r#"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sed nisi leo. Donec commodo in ex at aliquam. Nunc in aliquam arcu. Fusce mollis metus orci, ut sagittis erat lobortis sed. Morbi quis arcu ultrices turpis finibus tincidunt non in purus. Donec gravida condimentum sapien. Duis iaculis fermentum congue. Quisque blandit libero a lacus auctor vestibulum. Nunc efficitur sollicitudin nisi, sit amet tristique lectus mollis non. Praesent sit amet erat volutpat, pharetra orci eget, rutrum felis. Sed elit augue, imperdiet eu facilisis vel, finibus vel urna. Duis quis neque metus. | ||
Mauris suscipit bibendum mattis. Vestibulum eu augue diam. Morbi dapibus tempus viverra. Sed aliquam turpis eget justo ornare maximus vitae et tortor. Donec semper neque sit amet sapien congue scelerisque. Maecenas bibendum imperdiet dolor interdum facilisis. Integer non diam tempus, pharetra ex at, euismod diam. Ut enim turpis, sagittis in iaculis ut, finibus et sem. Suspendisse a felis euismod neque euismod placerat. Praesent ipsum libero, porta vel egestas quis, aliquet vitae lorem. Nullam vel pharetra erat, sit amet sodales leo."# | ||
))); | ||
|
||
c.bench_function("t_with_locale", |b| b.iter(|| t!("hello", locale = "en"))); | ||
|
||
c.bench_function("tr_with_threads", |b| { | ||
let exit_loop = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); | ||
let mut handles = Vec::new(); | ||
for _ in 0..4 { | ||
let exit_loop = exit_loop.clone(); | ||
handles.push(std::thread::spawn(move || { | ||
while !exit_loop.load(std::sync::atomic::Ordering::SeqCst) { | ||
criterion::black_box(t!("hello")); | ||
} | ||
})); | ||
} | ||
b.iter(|| t!("hello")); | ||
exit_loop.store(true, std::sync::atomic::Ordering::SeqCst); | ||
for handle in handles { | ||
handle.join().unwrap(); | ||
} | ||
}); | ||
|
||
c.bench_function("tr_with_args", |b| { | ||
b.iter(|| { | ||
t!( | ||
"Hello, %{name}. Your message is: %{msg}", | ||
name = "Jason", | ||
msg = "Bla bla" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("tr_with_args (str)", |b| { | ||
b.iter(|| { | ||
t!( | ||
"Hello, %{name}. Your message is: %{msg}", | ||
"name" = "Jason", | ||
"msg" = "Bla bla" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("tr_with_args (many)", |b| { | ||
b.iter(|| { | ||
t!( | ||
r#"Hello %{name} %{surname}, your account id is %{id}, email address is %{email}. | ||
You live in %{city} %{zip}. | ||
Your website is %{website}."#, | ||
id = 123, | ||
name = "Marion", | ||
surname = "Christiansen", | ||
email = "[email protected]", | ||
city = "Litteltown", | ||
zip = 8408, | ||
website = "https://snoopy-napkin.name" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("t_with_args (many-dynamic)", |b| { | ||
let msg = r#"Hello %{name} %{surname}, your account id is %{id}, email address is %{email}. | ||
You live in %{city} %{zip}. | ||
Your website is %{website}."# | ||
.to_string(); | ||
b.iter(|| { | ||
t!( | ||
&msg, | ||
id = 123, | ||
name = "Marion", | ||
surname = "Christiansen", | ||
email = "[email protected]", | ||
city = "Litteltown", | ||
zip = 8408, | ||
website = "https://snoopy-napkin.name" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("format! (many)", |b| { | ||
b.iter(|| { | ||
format!( | ||
r#"Hello {name} %{surname}, your account id is {id}, email address is {email}. | ||
You live in {city} {zip}. | ||
Your website is {website}."#, | ||
id = 123, | ||
name = "Marion", | ||
surname = "Christiansen", | ||
email = "[email protected]", | ||
city = "Litteltown", | ||
zip = 8408, | ||
website = "https://snoopy-napkin.name" | ||
); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_t); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.