Skip to content

Commit

Permalink
chore: use codspeed for benchmark (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Nov 28, 2023
1 parent d5a6af2 commit 3d77389
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/Bench.yaml.bak → .github/workflows/Bench.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ jobs:
- name: Install Rust
uses: moonrepo/setup-rust@v1

- name: Run benchmark(Rust)
run: cargo bench | tee output_rust.txt
- name: Install codspeed
uses: taiki-e/install-action@v2
with:
tool: cargo-codspeed

- name: Build Benchmark
run: cargo codspeed build --features codspeed

- name: Store benchmark result(Rust)
uses: benchmark-action/github-action-benchmark@v1
- name: Run benchmark
uses: CodSpeedHQ/action@v1
timeout-minutes: 30
with:
tool: 'cargo'
output-file-path: output_rust.txt
auto-push: true
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-always: true
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ readme = "README.md"

include = ["/src/**/*.rs", "/*.toml", "/LICENSE", "/README.md"]

[[bench]]
name = "bench"
harness = false

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand All @@ -26,7 +30,13 @@ smallvec = "1.10.0"
memchr = "2.5.0"
str_indices = "0.4.1"

codspeed-criterion-compat = { version = "2.3.3", default-features = false, optional = true }

[dev-dependencies]
twox-hash = "1"
base64-simd = "0.7"
regex = "1.8.1"
criterion = { version = "0.5.1", default-features = false }

[features]
codspeed = ["codspeed-criterion-compat"]
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# rspack-sources

Rusty [`webpack-sources`](https://github.com/webpack/webpack-sources) port.
[![Test](https://github.com/web-infra-dev/rspack-sources/actions/workflows/Test.yaml/badge.svg?branch=main)](https://github.com/web-infra-dev/rspack-sources/actions/workflows/Test.yaml)
[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/web-infra-dev/rspack-sources)

## Benchmark

you could check benchmark history and trending here: https://web-infra-dev.github.io/rspack-sources/dev/bench/
Rust port of [`webpack-sources`](https://github.com/webpack/webpack-sources).
34 changes: 26 additions & 8 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![feature(test)]
#![allow(soft_unstable)]
#[cfg(not(codspeed))]
pub use criterion::*;

extern crate test;
use test::Bencher;
#[cfg(codspeed)]
pub use codspeed_criterion_compat::*;

use rspack_sources::{
CachedSource, ConcatSource, MapOptions, Source, SourceMap, SourceMapSource,
Expand Down Expand Up @@ -34,7 +34,6 @@ const BUNDLE_JS_MAP: &str = include_str!(concat!(
"/benches/fixtures/transpile-rollup/files/bundle.js.map"
));

#[bench]
fn benchmark_concat_generate_string(b: &mut Bencher) {
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
value: HELLOWORLD_MIN_JS,
Expand All @@ -44,6 +43,7 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
inner_source_map: Some(SourceMap::from_json(HELLOWORLD_JS_MAP).unwrap()),
remove_original_source: false,
});

let sms_rollup = SourceMapSource::new(SourceMapSourceOptions {
value: BUNDLE_JS,
name: "bundle.js",
Expand All @@ -52,6 +52,7 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
inner_source_map: None,
remove_original_source: false,
});

let concat = ConcatSource::new([sms_minify, sms_rollup]);

b.iter(|| {
Expand All @@ -63,7 +64,6 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
})
}

#[bench]
fn benchmark_concat_generate_string_with_cache(b: &mut Bencher) {
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
value: HELLOWORLD_MIN_JS,
Expand Down Expand Up @@ -93,7 +93,6 @@ fn benchmark_concat_generate_string_with_cache(b: &mut Bencher) {
})
}

#[bench]
fn benchmark_concat_generate_base64(b: &mut Bencher) {
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
value: HELLOWORLD_MIN_JS,
Expand Down Expand Up @@ -123,7 +122,6 @@ fn benchmark_concat_generate_base64(b: &mut Bencher) {
})
}

#[bench]
fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
value: HELLOWORLD_MIN_JS,
Expand Down Expand Up @@ -153,3 +151,23 @@ fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
base64_simd::Base64::STANDARD.encode_to_boxed_str(json.as_bytes());
})
}

fn bench_rspack_sources(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("rspack_sources");
group.bench_function(
"concat_generate_base64_with_cache",
benchmark_concat_generate_base64_with_cache,
);
group
.bench_function("concat_generate_base64", benchmark_concat_generate_base64);
group.bench_function(
"concat_generate_string_with_cache",
benchmark_concat_generate_string_with_cache,
);
group
.bench_function("concat_generate_string", benchmark_concat_generate_string);
group.finish();
}

criterion_group!(rspack_sources, bench_rspack_sources);
criterion_main!(rspack_sources);

0 comments on commit 3d77389

Please sign in to comment.