Skip to content

Commit

Permalink
Add some benchmarks (#35)
Browse files Browse the repository at this point in the history
* Add some benchmarks

* Only run bench.yml with performance tag

* Revert "Only run bench.yml with performance tag"

This reverts commit e5266be.

* Rename CI step
  • Loading branch information
lukechu10 authored Mar 10, 2021
1 parent 9f4d282 commit 5325c62
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Run cargo bench on head
run: cargo bench

- name: upload benchmark report
- name: Upload benchmark report
uses: actions/upload-artifact@v2
with:
name: Benchmark report
Expand Down
7 changes: 7 additions & 0 deletions maple-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ features = [
"Window",
]
version = "0.3.48"

[dev-dependencies]
criterion = {version = "0.3", features = ["html_reports"]}

[[bench]]
harness = false
name = "reactivity"
31 changes: 31 additions & 0 deletions maple-core/benches/reactivity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use maple_core::prelude::*;

pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("reactivity signals run get/set 1000x", |b| {
b.iter(|| {
let state = Signal::new(black_box(0));

for _i in 0..1000 {
let value = state.get();
state.set(*value + 1);
}
})
});

c.bench_function("reactivity run effects 1000x", |b| {
b.iter(|| {
let state = Signal::new(black_box(0));
create_effect(cloned!((state) => move || {
let _double = *state.get() * 2;
}));

for _i in 0..1000 {
state.set(*state.get() + 1);
}
})
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

1 comment on commit 5325c62

@vercel
Copy link

@vercel vercel bot commented on 5325c62 Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.