From d61f8abd412e001ee1c57ca38921de412d050c0c Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Wed, 20 May 2020 00:15:05 -0400 Subject: [PATCH] add benches --- Cargo.toml | 14 ++++++++++++++ benches/control_flow.rs | 11 +++++++++++ benches/numbers.rs | 27 +++++++++++++++++++++++++++ benches/styles.rs | 11 +++++++++++ 4 files changed, 63 insertions(+) create mode 100644 benches/control_flow.rs create mode 100644 benches/numbers.rs create mode 100644 benches/styles.rs diff --git a/Cargo.toml b/Cargo.toml index 1cdc1e1..c23c280 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,19 @@ name = "grass" path = "src/lib.rs" crate-type = ["cdylib", "rlib"] +[[bench]] +name = "numbers" +harness = false + +[[bench]] +name = "control_flow" +harness = false + +[[bench]] +name = "styles" +harness = false + + [dependencies] clap = { version = "2.33.0", optional = true } num-rational = "0.2.3" @@ -49,6 +62,7 @@ profiling = [] [dev-dependencies] tempfile = "3" paste = "0.1" +criterion = "0.3.2" [profile.release] debug = true diff --git a/benches/control_flow.rs b/benches/control_flow.rs new file mode 100644 index 0000000..0f50dee --- /dev/null +++ b/benches/control_flow.rs @@ -0,0 +1,11 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use grass::StyleSheet; + +pub fn big_for(c: &mut Criterion) { + c.bench_function("big_for", |b| { + b.iter(|| StyleSheet::new(black_box(include_str!("big_for.scss").to_string()))) + }); +} + +criterion_group!(benches, big_for); +criterion_main!(benches); diff --git a/benches/numbers.rs b/benches/numbers.rs new file mode 100644 index 0000000..023bc01 --- /dev/null +++ b/benches/numbers.rs @@ -0,0 +1,27 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use grass::StyleSheet; + +pub fn many_floats(c: &mut Criterion) { + c.bench_function("many_floats", |b| { + b.iter(|| StyleSheet::new(black_box(include_str!("many_floats.scss").to_string()))) + }); +} + +pub fn many_integers(c: &mut Criterion) { + c.bench_function("many_integers", |b| { + b.iter(|| StyleSheet::new(black_box(include_str!("many_integers.scss").to_string()))) + }); +} + +pub fn many_small_integers(c: &mut Criterion) { + c.bench_function("many_small_integers", |b| { + b.iter(|| { + StyleSheet::new(black_box( + include_str!("many_small_integers.scss").to_string(), + )) + }) + }); +} + +criterion_group!(benches, many_floats, many_integers, many_small_integers); +criterion_main!(benches); diff --git a/benches/styles.rs b/benches/styles.rs new file mode 100644 index 0000000..a26102f --- /dev/null +++ b/benches/styles.rs @@ -0,0 +1,11 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use grass::StyleSheet; + +pub fn many_foo(c: &mut Criterion) { + c.bench_function("many_foo", |b| { + b.iter(|| StyleSheet::new(black_box(include_str!("many_foo.scss").to_string()))) + }); +} + +criterion_group!(benches, many_foo); +criterion_main!(benches);