-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add benchmark for base64 #8768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add benchmark for base64 #8768
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // This file is part of the uutils coreutils package. | ||
| // | ||
| // For the full copyright and license information, please view the LICENSE | ||
| // file that was distributed with this source code. | ||
|
|
||
| use divan::{Bencher, black_box}; | ||
| use std::ffi::OsString; | ||
| use uu_base64::uumain; | ||
| use uucore::benchmark::{create_test_file, run_util_function, text_data}; | ||
|
|
||
| fn create_tmp_file(size_mb: usize) -> String { | ||
| let temp_dir = tempfile::tempdir().unwrap(); | ||
| let data = text_data::generate_by_size(size_mb, 80); | ||
| let file_path = create_test_file(&data, temp_dir.path()); | ||
| String::from(file_path.to_str().unwrap()) | ||
| } | ||
|
|
||
| /// Benchmark for base64 encoding | ||
| #[divan::bench()] | ||
| fn b64_encode_synthetic(bencher: Bencher) { | ||
| let file_path_str = &create_tmp_file(5_000); | ||
|
|
||
| bencher.bench(|| { | ||
| black_box(run_util_function(uumain, &[file_path_str])); | ||
| }); | ||
| } | ||
|
|
||
| // Benchmark for base64 decoding | ||
| #[divan::bench()] | ||
| fn b64_decode_synthetic(bencher: Bencher) { | ||
| let temp_dir = tempfile::tempdir().unwrap(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. look like it is duplicated code with the two other tests ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this, I see wc_bench is also the same... but I can make a function that at least takes away the first part
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could also improve wc_bench then :) |
||
| let file_path_str = &create_tmp_file(5_000); | ||
| let in_file = create_test_file(b"", temp_dir.path()); | ||
| let in_file_str = in_file.to_str().unwrap(); | ||
| uumain( | ||
| [ | ||
| OsString::from(file_path_str), | ||
| OsString::from(format!(">{in_file_str}")), | ||
| ] | ||
| .iter() | ||
| .map(|x| (*x).clone()), | ||
| ); | ||
|
|
||
| bencher.bench(|| { | ||
| black_box(run_util_function(uumain, &["-d", in_file_str])); | ||
| }); | ||
| } | ||
|
|
||
| // Benchmark different file sizes for base64 decoding ignoring garbage characters | ||
| #[divan::bench()] | ||
| fn b64_decode_ignore_garbage_synthetic(bencher: Bencher) { | ||
| let temp_dir = tempfile::tempdir().unwrap(); | ||
| let file_path_str = &create_tmp_file(5_000); | ||
| let in_file = create_test_file(b"", temp_dir.path()); | ||
| let in_file_str = in_file.to_str().unwrap(); | ||
| uumain( | ||
| [ | ||
| OsString::from(file_path_str), | ||
| OsString::from(format!(">{in_file_str}")), | ||
| ] | ||
| .iter() | ||
| .map(|x| (*x).clone()), | ||
| ); | ||
|
|
||
| bencher.bench(|| { | ||
| black_box(run_util_function(uumain, &["-d", "-i", in_file_str])); | ||
| }); | ||
| } | ||
|
|
||
| fn main() { | ||
| divan::main(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.