Skip to content

Commit

Permalink
Use Codspeed for continous benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 26, 2023
1 parent 9d77552 commit 7945140
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
6 changes: 5 additions & 1 deletion crates/ruff_benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ serde.workspace = true
serde_json.workspace = true
url = "2.3.1"
ureq = "2.6.2"
criterion = { version = "0.5.1"}
codspeed-criterion-compat = { version="2.1.0", optional = true}

[dev-dependencies]
ruff.path = "../ruff"
ruff_python_ast.path = "../ruff_python_ast"
ruff_python_formatter = { path = "../ruff_python_formatter" }
ruff_python_index = { path = "../ruff_python_index" }
ruff_python_parser = { path = "../ruff_python_parser" }
criterion = { version = "0.5.1"}

[features]
codspeed = ["codspeed-criterion-compat"]

[target.'cfg(target_os = "windows")'.dev-dependencies]
mimalloc = "0.1.34"
Expand Down
5 changes: 3 additions & 2 deletions crates/ruff_benchmark/benches/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::path::Path;
use std::time::Duration;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};

use ruff_benchmark::criterion::{
criterion_group, criterion_main, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestCaseSpeed, TestFile, TestFileDownloadError};
use ruff_python_formatter::{format_node, PyFormatOptions};
use ruff_python_index::CommentRangesBuilder;
Expand Down
10 changes: 4 additions & 6 deletions crates/ruff_benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::time::Duration;

use criterion::measurement::WallTime;
use criterion::{
criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, Throughput,
};

use ruff::linter::lint_only;
use ruff::settings::{flags, Settings};
use ruff::source_kind::SourceKind;
use ruff::RuleSelector;
use ruff_benchmark::criterion::{
criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestCaseSpeed, TestFile, TestFileDownloadError};
use ruff_python_ast::PySourceType;

Expand Down Expand Up @@ -43,7 +41,7 @@ fn create_test_cases() -> Result<Vec<TestCase>, TestFileDownloadError> {
])
}

fn benchmark_linter(mut group: BenchmarkGroup<WallTime>, settings: &Settings) {
fn benchmark_linter(mut group: BenchmarkGroup, settings: &Settings) {
let test_cases = create_test_cases().unwrap();

for case in test_cases {
Expand Down
5 changes: 3 additions & 2 deletions crates/ruff_benchmark/benches/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::time::Duration;

use criterion::measurement::WallTime;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use ruff_benchmark::criterion::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestCaseSpeed, TestFile, TestFileDownloadError};
use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
use ruff_python_ast::Stmt;
Expand Down
11 changes: 11 additions & 0 deletions crates/ruff_benchmark/src/criterion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! This module re-exports the criterion API but picks the right backend depending on whether
//! the benchmarks are built to run locally or with codspeed

#[cfg(not(codspeed))]
pub use criterion::*;

#[cfg(not(codspeed))]
pub type BenchmarkGroup<'a> = criterion::BenchmarkGroup<'a, measurement::WallTime>;

#[cfg(codspeed)]
pub use codspeed_criterion_compat::*;
2 changes: 2 additions & 0 deletions crates/ruff_benchmark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod criterion;

use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use std::process::Command;
Expand Down

0 comments on commit 7945140

Please sign in to comment.