Remove criterion/codspeed compat layer (#12524)

This commit is contained in:
Micha Reiser 2024-07-26 12:22:16 +02:00 committed by GitHub
parent 9f72f474e6
commit 71f7aa4971
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 25 additions and 52 deletions

View file

@ -616,7 +616,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: "Build benchmarks"
run: cargo codspeed build --features codspeed -p ruff_benchmark
run: cargo codspeed build -p ruff_benchmark
- name: "Run benchmarks"
uses: CodSpeedHQ/action@v2

1
Cargo.lock generated
View file

@ -2048,7 +2048,6 @@ name = "ruff_benchmark"
version = "0.0.0"
dependencies = [
"codspeed-criterion-compat",
"criterion",
"mimalloc",
"once_cell",
"red_knot",

View file

@ -58,7 +58,6 @@ console_error_panic_hook = { version = "0.1.7" }
console_log = { version = "1.0.0" }
countme = { version = "3.0.1" }
compact_str = "0.8.0"
criterion = { version = "0.5.1", default-features = false }
crossbeam = { version = "0.8.4" }
dashmap = { version = "6.0.1" }
drop_bomb = { version = "0.1.5" }

View file

@ -41,8 +41,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
url = { workspace = true }
ureq = { workspace = true }
criterion = { workspace = true, default-features = false }
codspeed-criterion-compat = { workspace = true, default-features = false, optional = true }
codspeed-criterion-compat = { workspace = true, default-features = false }
[dev-dependencies]
ruff_db = { workspace = true }
@ -56,9 +55,6 @@ red_knot = { workspace = true }
[lints]
workspace = true
[features]
codspeed = ["codspeed-criterion-compat"]
[target.'cfg(target_os = "windows")'.dev-dependencies]
mimalloc = { workspace = true }

View file

@ -1,8 +1,9 @@
use std::path::Path;
use ruff_benchmark::criterion::{
use codspeed_criterion_compat::{
criterion_group, criterion_main, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError};
use ruff_python_formatter::{format_module_ast, PreviewMode, PyFormatOptions};
use ruff_python_parser::{parse, Mode};

View file

@ -1,6 +1,7 @@
use ruff_benchmark::criterion::{
use codspeed_criterion_compat::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError};
use ruff_python_parser::{lexer, Mode, TokenKind};

View file

@ -1,6 +1,8 @@
use ruff_benchmark::criterion::{
criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, Throughput,
use codspeed_criterion_compat::{
self as criterion, criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion,
Throughput,
};
use criterion::measurement;
use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError};
use ruff_linter::linter::{lint_only, ParseSource};
use ruff_linter::rule_selector::PreviewOptions;
@ -44,7 +46,7 @@ fn create_test_cases() -> Result<Vec<TestCase>, TestFileDownloadError> {
])
}
fn benchmark_linter(mut group: BenchmarkGroup, settings: &LinterSettings) {
fn benchmark_linter(mut group: BenchmarkGroup<measurement::WallTime>, settings: &LinterSettings) {
let test_cases = create_test_cases().unwrap();
for case in test_cases {

View file

@ -1,6 +1,7 @@
use ruff_benchmark::criterion::{
use codspeed_criterion_compat::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput,
};
use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError};
use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
use ruff_python_ast::Stmt;

View file

@ -1,10 +1,9 @@
#![allow(clippy::disallowed_names)]
use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion};
use red_knot::db::RootDatabase;
use red_knot::workspace::WorkspaceMetadata;
use ruff_benchmark::criterion::{
criterion_group, criterion_main, BatchSize, Criterion, Throughput,
};
use ruff_db::files::{system_path_to_file, vendored_path_to_file, File};
use ruff_db::parsed::parsed_module;
use ruff_db::program::{ProgramSettings, SearchPathSettings, TargetVersion};
@ -100,10 +99,7 @@ fn setup_case() -> Case {
}
fn benchmark_without_parse(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("red_knot/check_file");
group.throughput(Throughput::Bytes(FOO_CODE.len() as u64));
group.bench_function("red_knot_check_file[without_parse]", |b| {
criterion.bench_function("red_knot_check_file[without_parse]", |b| {
b.iter_batched_ref(
|| {
let case = setup_case();
@ -123,15 +119,10 @@ fn benchmark_without_parse(criterion: &mut Criterion) {
BatchSize::SmallInput,
);
});
group.finish();
}
fn benchmark_incremental(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("red_knot/check_file");
group.throughput(Throughput::Bytes(FOO_CODE.len() as u64));
group.bench_function("red_knot_check_file[incremental]", |b| {
criterion.bench_function("red_knot_check_file[incremental]", |b| {
b.iter_batched_ref(
|| {
let mut case = setup_case();
@ -156,15 +147,10 @@ fn benchmark_incremental(criterion: &mut Criterion) {
BatchSize::SmallInput,
);
});
group.finish();
}
fn benchmark_cold(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("red_knot/check_file");
group.throughput(Throughput::Bytes(FOO_CODE.len() as u64));
group.bench_function("red_knot_check_file[cold]", |b| {
criterion.bench_function("red_knot_check_file[cold]", |b| {
b.iter_batched_ref(
setup_case,
|case| {
@ -176,11 +162,12 @@ fn benchmark_cold(criterion: &mut Criterion) {
BatchSize::SmallInput,
);
});
group.finish();
}
criterion_group!(cold, benchmark_cold);
criterion_group!(without_parse, benchmark_without_parse);
criterion_group!(incremental, benchmark_incremental);
criterion_main!(without_parse, cold, incremental);
criterion_group!(
check_file,
benchmark_cold,
benchmark_without_parse,
benchmark_incremental
);
criterion_main!(check_file);

View file

@ -1,11 +0,0 @@
//! 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::*;

View file

@ -1,5 +1,3 @@
pub mod criterion;
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use std::process::Command;