Skip to content
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

[feat] trait bounds for char and u8 on Source trait #10

Merged
merged 10 commits into from Dec 19, 2023
1 change: 1 addition & 0 deletions benches/bench_main.rs
Expand Up @@ -4,4 +4,5 @@ mod benchmarks;
criterion_main! {
benchmarks::format_whitespace_leftalign::formats,
benchmarks::pad_whitespace_leftalign::pads,
benchmarks::pad_wrapper_whitespace_leftalign::pads,
}
1 change: 1 addition & 0 deletions benches/benchmarks/mod.rs
@@ -1,2 +1,3 @@
pub mod format_whitespace_leftalign;
pub mod pad_whitespace_leftalign;
pub mod pad_wrapper_whitespace_leftalign;
26 changes: 13 additions & 13 deletions benches/benchmarks/pad_whitespace_leftalign.rs
@@ -1,26 +1,29 @@
use criterion::{black_box, criterion_group, Criterion};
use padder::whitespace;
use padder::Alignment;
use padder::*;

pub fn pad_whitespace_10_leftalign(c: &mut Criterion) {
let width: usize = 10;
c.bench_function("pad ws 10 la", |b| {
b.iter(|| black_box(whitespace("hej", width, Alignment::Left).unwrap()))
b.iter(|| black_box("hej".pad(width, Alignment::Left, Symbol::Whitespace)))
});
}

pub fn pad_whitespace_100_leftalign(c: &mut Criterion) {
let width: usize = 100;
c.bench_function("pad ws 100 la", |b| {
b.iter(|| black_box(whitespace("bingbong", width, Alignment::Left).unwrap()))
b.iter(|| black_box("bingbong".pad(width, Alignment::Left, Symbol::Whitespace)))
});
}

pub fn pad_whitespace_1000_leftalign(c: &mut Criterion) {
let width: usize = 1000;
c.bench_function("pad ws 1000 la", |b| {
b.iter(|| {
black_box(whitespace("Undercity is a cool capital...", width, Alignment::Left).unwrap())
black_box("Undercity is a cool capital...".pad(
width,
Alignment::Left,
Symbol::Whitespace,
))
})
});
}
Expand All @@ -29,14 +32,11 @@ pub fn pad_whitespace_10000_leftalign(c: &mut Criterion) {
let width: usize = 10000;
c.bench_function("pad ws 10000 la", |b| {
b.iter(|| {
black_box(
whitespace(
"¤)(åäöåa this is a very long string... xd",
width,
Alignment::Left,
)
.unwrap(),
)
black_box("¤)(åäöåa this is a very long string... xd".pad(
width,
Alignment::Left,
Symbol::Whitespace,
))
})
});
}
Expand Down
52 changes: 52 additions & 0 deletions benches/benchmarks/pad_wrapper_whitespace_leftalign.rs
@@ -0,0 +1,52 @@
use criterion::{black_box, criterion_group, Criterion};
use padder::*;

pub fn pad_wrapper_whitespace_10_leftalign(c: &mut Criterion) {
let width: usize = 10;
c.bench_function("pad wrapper ws 10 la", |b| {
b.iter(|| black_box(pad("hej", width, Alignment::Left, Symbol::Whitespace)))
});
}

pub fn pad_wrapper_whitespace_100_leftalign(c: &mut Criterion) {
let width: usize = 100;
c.bench_function("pad wrapper ws 100 la", |b| {
b.iter(|| black_box(pad("bingbong", width, Alignment::Left, Symbol::Whitespace)))
});
}

pub fn pad_wrapper_whitespace_1000_leftalign(c: &mut Criterion) {
let width: usize = 1000;
c.bench_function("pad wrapper ws 1000 la", |b| {
b.iter(|| {
black_box(pad(
"Undercity is a cool capital...",
width,
Alignment::Left,
Symbol::Whitespace,
))
})
});
}

pub fn pad_wrapper_whitespace_10000_leftalign(c: &mut Criterion) {
let width: usize = 10000;
c.bench_function("pad wrapper ws 10000 la", |b| {
b.iter(|| {
black_box(pad(
"¤)(åäöåa this is a very long string... xd",
width,
Alignment::Left,
Symbol::Whitespace,
))
})
});
}

criterion_group!(
pads,
pad_wrapper_whitespace_10_leftalign,
pad_wrapper_whitespace_100_leftalign,
pad_wrapper_whitespace_1000_leftalign,
pad_wrapper_whitespace_10000_leftalign,
);