Skip to content

Commit

Permalink
chore: add codspeed for benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
dqhl76 committed Aug 10, 2024
1 parent e42fe79 commit c7f0c2d
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 12 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/test_benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Benchmark Test

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "core/src/**"
- "core/benches/**"
- "!core/src/docs/**"
- ".github/workflows/test_benchmark.yml"
# `workflow_dispatch` is needed by codspeed for first time trigger
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: ./.github/actions/setup
- name: Setup codspeed
run: cargo install cargo-codspeed
- name: Setup Memory env
uses: ./.github/services/memory/memory
- name: Build the benchmark targets
run: cargo codspeed build --features tests
- name: Run the benchmarks
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
35 changes: 35 additions & 0 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ probe = { version = "0.5.1", optional = true }
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
codspeed-criterion-compat = { version = "2.6.0", features = ["async", "async_tokio"] }
criterion = { version = "0.5", features = ["async", "async_tokio"] }
dotenvy = "0.15"
fastrace = { version = "0.6", features = ["enable"] }
Expand Down
4 changes: 2 additions & 2 deletions core/benches/ops/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod read;
mod utils;
mod write;

use criterion::criterion_group;
use criterion::criterion_main;
use codspeed_criterion_compat::criterion_group;
use codspeed_criterion_compat::criterion_main;

criterion_group!(benches, read::bench, write::bench);
criterion_main!(benches);
7 changes: 4 additions & 3 deletions core/benches/ops/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// specific language governing permissions and limitations
// under the License.

use criterion::Criterion;
use codspeed_criterion_compat::Criterion;
use codspeed_criterion_compat::Throughput;
use futures::io;
use opendal::raw::tests::init_test_service;
use opendal::raw::tests::TEST_RUNTIME;
Expand Down Expand Up @@ -47,7 +48,7 @@ fn bench_read_full(c: &mut Criterion, name: &str, op: Operator) {
let path = uuid::Uuid::new_v4().to_string();
let temp_data = TempData::generate(op.clone(), &path, content.clone());

group.throughput(criterion::Throughput::Bytes(size.bytes() as u64));
group.throughput(Throughput::Bytes(size.bytes() as u64));
group.bench_with_input(size.to_string(), &(op.clone(), &path), |b, (op, path)| {
b.to_async(&*TEST_RUNTIME).iter(|| async {
let r = op.reader_with(path).await.unwrap();
Expand Down Expand Up @@ -84,7 +85,7 @@ fn bench_read_parallel(c: &mut Criterion, name: &str, op: Operator) {
let temp_data = TempData::generate(op.clone(), &path, content.clone());

for parallel in [1, 2, 4, 8, 16] {
group.throughput(criterion::Throughput::Bytes(parallel * size.bytes() as u64));
group.throughput(Throughput::Bytes(parallel * size.bytes() as u64));
group.bench_with_input(
format!("{}x{}", parallel, size.to_string()),
&(op.clone(), &path, buf_size),
Expand Down
2 changes: 1 addition & 1 deletion core/benches/ops/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use criterion::Criterion;
use codspeed_criterion_compat::Criterion;
use opendal::raw::tests::init_test_service;
use opendal::raw::tests::TEST_RUNTIME;
use opendal::Operator;
Expand Down
6 changes: 4 additions & 2 deletions core/benches/types/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
// under the License.

use bytes::Buf;
use criterion::Criterion;
use codspeed_criterion_compat::Criterion;
use codspeed_criterion_compat::measurement::WallTime;
use codspeed_criterion_compat::BenchmarkGroup;
use opendal::Buffer;
use rand::thread_rng;
use size::Size;
Expand Down Expand Up @@ -83,7 +85,7 @@ pub fn bench_non_contiguous_buffer(c: &mut Criterion) {
}

pub fn bench_non_contiguous_buffer_with_extreme(c: &mut Criterion) {
let mut group: criterion::BenchmarkGroup<criterion::measurement::WallTime> =
let mut group: BenchmarkGroup<WallTime> =
c.benchmark_group("bench_non_contiguous_buffer_with_extreme");

let mut rng = thread_rng();
Expand Down
4 changes: 2 additions & 2 deletions core/benches/types/concurrent_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

use std::time::Duration;

use criterion::BatchSize;
use criterion::Criterion;
use codspeed_criterion_compat::BatchSize;
use codspeed_criterion_compat::Criterion;
use once_cell::sync::Lazy;
use opendal::raw::ConcurrentTasks;
use opendal::Executor;
Expand Down
4 changes: 2 additions & 2 deletions core/benches/types/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod buffer;
mod concurrent_tasks;
mod utils;

use criterion::criterion_group;
use criterion::criterion_main;
use codspeed_criterion_compat::criterion_group;
use codspeed_criterion_compat::criterion_main;

criterion_group!(
benches,
Expand Down

0 comments on commit c7f0c2d

Please sign in to comment.