mirror of
https://github.com/swc-project/swc.git
synced 2024-12-19 03:31:45 +03:00
77 lines
1.5 KiB
Rust
77 lines
1.5 KiB
Rust
|
//! These benchmarks ensures that adding a Noop to chain! does not affect
|
||
|
//! performance.
|
||
|
|
||
|
#![feature(box_patterns)]
|
||
|
#![feature(box_syntax)]
|
||
|
#![feature(specialization)]
|
||
|
#![feature(test)]
|
||
|
|
||
|
#[macro_use]
|
||
|
extern crate swc_common;
|
||
|
extern crate test;
|
||
|
|
||
|
use swc_common::FoldWith;
|
||
|
use test::{black_box, Bencher};
|
||
|
|
||
|
fn mk_vec() -> Vec<Box<String>> {
|
||
|
(0..1000).map(|s| box s.to_string()).collect()
|
||
|
}
|
||
|
|
||
|
struct Noop;
|
||
|
|
||
|
#[bench]
|
||
|
fn bench_vec_chain2(b: &mut Bencher) {
|
||
|
let mut chain = chain!(Noop, Noop);
|
||
|
b.iter(|| {
|
||
|
let v = mk_vec();
|
||
|
black_box(v.fold_with(&mut chain))
|
||
|
})
|
||
|
}
|
||
|
|
||
|
#[bench]
|
||
|
fn bench_vec_chain3(b: &mut Bencher) {
|
||
|
let mut chain = chain!(Noop, Noop, Noop);
|
||
|
b.iter(|| {
|
||
|
let v = mk_vec();
|
||
|
black_box(v.fold_with(&mut chain))
|
||
|
})
|
||
|
}
|
||
|
|
||
|
#[bench]
|
||
|
fn bench_vec_chain4(b: &mut Bencher) {
|
||
|
let mut chain = chain!(Noop, Noop, Noop, Noop);
|
||
|
b.iter(|| {
|
||
|
let v = mk_vec();
|
||
|
black_box(v.fold_with(&mut chain))
|
||
|
})
|
||
|
}
|
||
|
|
||
|
#[bench]
|
||
|
fn bench_vec_chain5(b: &mut Bencher) {
|
||
|
let mut chain = chain!(Noop, Noop, Noop, Noop, Noop);
|
||
|
b.iter(|| {
|
||
|
let v = mk_vec();
|
||
|
black_box(v.fold_with(&mut chain))
|
||
|
})
|
||
|
}
|
||
|
#[bench]
|
||
|
fn bench_mk_vec(b: &mut Bencher) {
|
||
|
b.iter(|| {
|
||
|
black_box(mk_vec());
|
||
|
})
|
||
|
}
|
||
|
|
||
|
#[bench]
|
||
|
fn bench_vec_5(b: &mut Bencher) {
|
||
|
b.iter(|| {
|
||
|
let v = mk_vec();
|
||
|
black_box(
|
||
|
v.fold_with(&mut Noop)
|
||
|
.fold_with(&mut Noop)
|
||
|
.fold_with(&mut Noop)
|
||
|
.fold_with(&mut Noop)
|
||
|
.fold_with(&mut Noop),
|
||
|
)
|
||
|
});
|
||
|
}
|