Skip to content

Commit

Permalink
Ran cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
gammelalf committed Jun 15, 2022
1 parent 17b0f73 commit 3cfdc4e
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 258 deletions.
2 changes: 1 addition & 1 deletion benches/common.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod bezier;
pub mod samples;
pub mod bezier;
7 changes: 4 additions & 3 deletions benches/common/bezier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::samples::CURVES;
use criterion::{black_box, Criterion};
use nbezier::bezier::BezierCurve;
use crate::common::samples::CURVES;

macro_rules! bench_curve_types {
($group:ident, $body:expr) => {
Expand All @@ -24,7 +24,7 @@ macro_rules! bench_curve_types {
b.iter(|| $body(curve))
}
});
}
};
}

pub fn split(c: &mut Criterion) {
Expand All @@ -34,7 +34,8 @@ pub fn split(c: &mut Criterion) {

pub fn castlejau_eval(c: &mut Criterion) {
let mut g = c.benchmark_group("BezierCurve::castlejau_eval");
bench_curve_types!(g, |curve: &BezierCurve<f64>| curve.castlejau_eval(black_box(0.5)));
bench_curve_types!(g, |curve: &BezierCurve<f64>| curve
.castlejau_eval(black_box(0.5)));
}

pub fn normal(c: &mut Criterion) {
Expand Down
29 changes: 15 additions & 14 deletions benches/common/samples.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use once_cell::sync::Lazy;
use smallvec::smallvec;
use nalgebra::Vector2;
use nbezier::bezier::BezierCurve;
use once_cell::sync::Lazy;
use smallvec::smallvec;

/// Points generated randomly
/// ```python
Expand All @@ -10,16 +10,16 @@ use nbezier::bezier::BezierCurve;
/// print(f"Vector2::new({(random()-0.5)*i}, {(random()-0.5)*i})")
/// ```
pub static POINTS: [Vector2<f64>; 10] = [
Vector2::new( 0.0, 0.0 ),
Vector2::new(-0.29734, 0.44984),
Vector2::new(-0.52560, 0.42885),
Vector2::new( 1.42777, -0.02652),
Vector2::new( 1.98032, -0.67824),
Vector2::new( 0.44863, -0.91328),
Vector2::new(0.0, 0.0),
Vector2::new(-0.29734, 0.44984),
Vector2::new(-0.52560, 0.42885),
Vector2::new(1.42777, -0.02652),
Vector2::new(1.98032, -0.67824),
Vector2::new(0.44863, -0.91328),
Vector2::new(-2.51139, -0.79100),
Vector2::new(-3.10479, -0.59318),
Vector2::new(-1.16022, -2.95591),
Vector2::new(-1.07946, 0.78888),
Vector2::new(-1.07946, 0.78888),
];

pub static CURVES: Lazy<Curves> = Lazy::new(Curves::new);
Expand All @@ -33,7 +33,7 @@ pub struct Curves {
impl Curves {
pub fn new() -> Curves {
Curves {
LINEAR: vec![
LINEAR: vec![
BezierCurve([0, 1].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([1, 2].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([2, 3].into_iter().map(|i| POINTS[i]).collect()),
Expand All @@ -57,7 +57,7 @@ impl Curves {
BezierCurve([1, 5, 3].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([5, 9, 7].into_iter().map(|i| POINTS[i]).collect()),
],
CUBIC: vec![
CUBIC: vec![
BezierCurve([0, 1, 2, 3].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([2, 3, 4, 5].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([4, 5, 6, 7].into_iter().map(|i| POINTS[i]).collect()),
Expand All @@ -69,7 +69,7 @@ impl Curves {
BezierCurve([3, 7, 5, 9].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([4, 8, 6, 0].into_iter().map(|i| POINTS[i]).collect()),
],
HIGHER: vec![
HIGHER: vec![
BezierCurve([0, 1, 2, 3, 4].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([2, 3, 4, 5, 6].into_iter().map(|i| POINTS[i]).collect()),
BezierCurve([4, 5, 6, 7, 8].into_iter().map(|i| POINTS[i]).collect()),
Expand All @@ -84,8 +84,9 @@ impl Curves {
}
}

pub fn iter(&self) -> impl Iterator<Item=&BezierCurve<f64>> {
self.LINEAR.iter()
pub fn iter(&self) -> impl Iterator<Item = &BezierCurve<f64>> {
self.LINEAR
.iter()
.chain(self.QUADRATIC.iter())
.chain(self.CUBIC.iter())
.chain(self.HIGHER.iter())
Expand Down
7 changes: 3 additions & 4 deletions benches/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
///
/// Needs to be called with `--profile-time=<seconds>`
///
use criterion::{criterion_group, criterion_main, Criterion};
use pprof::criterion::{PProfProfiler, Output};
use pprof::criterion::{Output, PProfProfiler};
mod common;

criterion_group!{
criterion_group! {
name = benches;
config = Criterion::default()
.with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)))
;
targets = common::bezier::all
}
criterion_main!(benches);
criterion_main!(benches);
7 changes: 3 additions & 4 deletions benches/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
///
/// Needs to be called with `--profile-time=<seconds>`
///
use criterion::{criterion_group, criterion_main, Criterion};
use pprof::criterion::{PProfProfiler, Output};
use pprof::criterion::{Output, PProfProfiler};
mod common;

criterion_group!{
criterion_group! {
name = benches;
config = Criterion::default()
.with_profiler(PProfProfiler::new(100, Output::Protobuf))
;
targets = common::bezier::all
}
criterion_main!(benches);
criterion_main!(benches);
4 changes: 2 additions & 2 deletions benches/speed.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::time::Duration;
use criterion::{criterion_group, criterion_main, Criterion};
use std::time::Duration;
mod common;

static SECOND: Duration = Duration::from_secs(1);
criterion_group!{
criterion_group! {
name = benches;
config = Criterion::default()
.warm_up_time(SECOND)
Expand Down
Loading

0 comments on commit 3cfdc4e

Please sign in to comment.