Skip to content

Commit 3d77389

Browse files
authored
chore: use codspeed for benchmark (#67)
1 parent d5a6af2 commit 3d77389

File tree

4 files changed

+51
-21
lines changed

4 files changed

+51
-21
lines changed

.github/workflows/Bench.yaml.bak renamed to .github/workflows/Bench.yaml

+12-9
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ jobs:
2929
- name: Install Rust
3030
uses: moonrepo/setup-rust@v1
3131

32-
- name: Run benchmark(Rust)
33-
run: cargo bench | tee output_rust.txt
32+
- name: Install codspeed
33+
uses: taiki-e/install-action@v2
34+
with:
35+
tool: cargo-codspeed
36+
37+
- name: Build Benchmark
38+
run: cargo codspeed build --features codspeed
3439

35-
- name: Store benchmark result(Rust)
36-
uses: benchmark-action/github-action-benchmark@v1
40+
- name: Run benchmark
41+
uses: CodSpeedHQ/action@v1
42+
timeout-minutes: 30
3743
with:
38-
tool: 'cargo'
39-
output-file-path: output_rust.txt
40-
auto-push: true
41-
github-token: ${{ secrets.GITHUB_TOKEN }}
42-
comment-always: true
44+
run: cargo codspeed run
45+
token: ${{ secrets.CODSPEED_TOKEN }}

Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ readme = "README.md"
1313

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

16+
[[bench]]
17+
name = "bench"
18+
harness = false
19+
1620
[dependencies]
1721
serde = { version = "1", features = ["derive"] }
1822
serde_json = "1"
@@ -26,7 +30,13 @@ smallvec = "1.10.0"
2630
memchr = "2.5.0"
2731
str_indices = "0.4.1"
2832

33+
codspeed-criterion-compat = { version = "2.3.3", default-features = false, optional = true }
34+
2935
[dev-dependencies]
3036
twox-hash = "1"
3137
base64-simd = "0.7"
3238
regex = "1.8.1"
39+
criterion = { version = "0.5.1", default-features = false }
40+
41+
[features]
42+
codspeed = ["codspeed-criterion-compat"]

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# rspack-sources
22

3-
Rusty [`webpack-sources`](https://github.com/webpack/webpack-sources) port.
3+
[![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)
4+
[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/web-infra-dev/rspack-sources)
45

5-
## Benchmark
6-
7-
you could check benchmark history and trending here: https://web-infra-dev.github.io/rspack-sources/dev/bench/
6+
Rust port of [`webpack-sources`](https://github.com/webpack/webpack-sources).

benches/bench.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#![feature(test)]
2-
#![allow(soft_unstable)]
1+
#[cfg(not(codspeed))]
2+
pub use criterion::*;
33

4-
extern crate test;
5-
use test::Bencher;
4+
#[cfg(codspeed)]
5+
pub use codspeed_criterion_compat::*;
66

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

37-
#[bench]
3837
fn benchmark_concat_generate_string(b: &mut Bencher) {
3938
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
4039
value: HELLOWORLD_MIN_JS,
@@ -44,6 +43,7 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
4443
inner_source_map: Some(SourceMap::from_json(HELLOWORLD_JS_MAP).unwrap()),
4544
remove_original_source: false,
4645
});
46+
4747
let sms_rollup = SourceMapSource::new(SourceMapSourceOptions {
4848
value: BUNDLE_JS,
4949
name: "bundle.js",
@@ -52,6 +52,7 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
5252
inner_source_map: None,
5353
remove_original_source: false,
5454
});
55+
5556
let concat = ConcatSource::new([sms_minify, sms_rollup]);
5657

5758
b.iter(|| {
@@ -63,7 +64,6 @@ fn benchmark_concat_generate_string(b: &mut Bencher) {
6364
})
6465
}
6566

66-
#[bench]
6767
fn benchmark_concat_generate_string_with_cache(b: &mut Bencher) {
6868
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
6969
value: HELLOWORLD_MIN_JS,
@@ -93,7 +93,6 @@ fn benchmark_concat_generate_string_with_cache(b: &mut Bencher) {
9393
})
9494
}
9595

96-
#[bench]
9796
fn benchmark_concat_generate_base64(b: &mut Bencher) {
9897
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
9998
value: HELLOWORLD_MIN_JS,
@@ -123,7 +122,6 @@ fn benchmark_concat_generate_base64(b: &mut Bencher) {
123122
})
124123
}
125124

126-
#[bench]
127125
fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
128126
let sms_minify = SourceMapSource::new(SourceMapSourceOptions {
129127
value: HELLOWORLD_MIN_JS,
@@ -153,3 +151,23 @@ fn benchmark_concat_generate_base64_with_cache(b: &mut Bencher) {
153151
base64_simd::Base64::STANDARD.encode_to_boxed_str(json.as_bytes());
154152
})
155153
}
154+
155+
fn bench_rspack_sources(criterion: &mut Criterion) {
156+
let mut group = criterion.benchmark_group("rspack_sources");
157+
group.bench_function(
158+
"concat_generate_base64_with_cache",
159+
benchmark_concat_generate_base64_with_cache,
160+
);
161+
group
162+
.bench_function("concat_generate_base64", benchmark_concat_generate_base64);
163+
group.bench_function(
164+
"concat_generate_string_with_cache",
165+
benchmark_concat_generate_string_with_cache,
166+
);
167+
group
168+
.bench_function("concat_generate_string", benchmark_concat_generate_string);
169+
group.finish();
170+
}
171+
172+
criterion_group!(rspack_sources, bench_rspack_sources);
173+
criterion_main!(rspack_sources);

0 commit comments

Comments
 (0)