Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 235 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ exclude = ["/.github"]
[dependencies]
unicode-width = { version = "0.2", default-features = false }
unicode-segmentation = "1.12"

[dev-dependencies]
divan = "0.1"

[[bench]]
name = "benches"
harness = false

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tinytable_profile_alloc)'] }
62 changes: 62 additions & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use std::num::NonZeroUsize;
use std::{io, iter};
use tinytable::write_table;

#[cfg(tinytable_profile_alloc)]
use divan::AllocProfiler;

#[cfg(tinytable_profile_alloc)]
#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
}

const COLUMNS: usize = 10;
const COLUMN_WIDTHS: [NonZeroUsize; COLUMNS] = [NonZeroUsize::new(10).unwrap(); COLUMNS];

#[divan::bench(args = [10, 100, 1000, 10000], types = [Vec<u8>, io::Empty])]
fn no_padding<W: io::Write + Default>(rows: usize) {
const S: &str = " ";
const ROW: [&str; COLUMNS] = [S; COLUMNS];

let mut output: W = Default::default();
write_table(&mut output, iter::repeat_n(ROW, rows), &ROW, &COLUMN_WIDTHS).expect("write_table failed");
}

#[divan::bench(args = [10, 100, 1000, 10000], types = [Vec<u8>, io::Empty])]
fn no_padding_unicode<W: io::Write + Default>(rows: usize) {
const S: &str = "あいうえお";
const ROW: [&str; COLUMNS] = [S; COLUMNS];

let mut output: W = Default::default();
write_table(&mut output, iter::repeat_n(ROW, rows), &ROW, &COLUMN_WIDTHS).expect("write_table failed");
}

#[divan::bench(args = [10, 100, 1000, 10000], types = [Vec<u8>, io::Empty])]
fn all_padding<W: io::Write + Default>(rows: usize) {
const S: &str = "";
const ROW: [&str; COLUMNS] = [S; COLUMNS];

let mut output: W = Default::default();
write_table(&mut output, iter::repeat_n(ROW, rows), &ROW, &COLUMN_WIDTHS).expect("write_table failed");
}

#[divan::bench(args = [10, 100, 1000, 10000], types = [Vec<u8>, io::Empty])]
fn single_padding<W: io::Write + Default>(rows: usize) {
const S: &str = " ";
const ROW: [&str; COLUMNS] = [S; COLUMNS];

let mut output: W = Default::default();
write_table(&mut output, iter::repeat_n(ROW, rows), &ROW, &COLUMN_WIDTHS).expect("write_table failed");
}

#[divan::bench(args = [10, 100, 1000, 10000], types = [Vec<u8>, io::Empty])]
fn too_long<W: io::Write + Default>(rows: usize) {
const S: &str = " ";
const ROW: [&str; COLUMNS] = [S; COLUMNS];

let mut output: W = Default::default();
write_table(&mut output, iter::repeat_n(ROW, rows), &ROW, &COLUMN_WIDTHS).expect("write_table failed");
}