From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- vendor/chalk-solve-0.87.0/src/solve/test/bench.rs | 111 ++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 vendor/chalk-solve-0.87.0/src/solve/test/bench.rs (limited to 'vendor/chalk-solve-0.87.0/src/solve/test/bench.rs') diff --git a/vendor/chalk-solve-0.87.0/src/solve/test/bench.rs b/vendor/chalk-solve-0.87.0/src/solve/test/bench.rs new file mode 100644 index 000000000..6ef6eb1f9 --- /dev/null +++ b/vendor/chalk-solve-0.87.0/src/solve/test/bench.rs @@ -0,0 +1,111 @@ +//! Benchmarking tests. + +extern crate test; +use self::test::Bencher; + +use crate::db::ChalkDatabase; +use crate::query::{ProgramSolverChoice, ProgramText}; +use chalk_solve::SolverChoice; +use ir; +use std::sync::Arc; + +use super::{assert_result, parse_and_lower_goal, parse_and_lower_program}; + +fn run_bench( + program_text: &str, + solver_choice: SolverChoice, + goal_text: &str, + bencher: &mut Bencher, + expected: &str, +) { + ChalkDatabase::with_program(Arc::new(program_text.to_string()), solver_choice, |db| { + let program = db.lowered_program().unwrap(); + let env = db.environment().unwrap(); + ir::tls::set_current_program(&program, || { + let goal = parse_and_lower_goal(&program, goal_text).unwrap(); + let peeled_goal = goal.into_peeled_goal(); + + // Execute once to get an expected result. + let result = solver_choice.solve_root_goal(&env, &peeled_goal); + + // Check expectation. + assert_result(&result, expected); + + // Then do it many times to measure time. + bencher.iter(|| solver_choice.solve_root_goal(&env, &peeled_goal)); + }); + }); +} + +const CYCLEY: &str = " +trait AsRef { } +trait Clone { } +trait Copy where Self: Clone { } +trait Sized { } + +struct i32 { } +impl Copy for i32 { } +impl Clone for i32 { } +impl Sized for i32 { } + +struct u32 { } +impl Copy for u32 { } +impl Clone for u32 { } +impl Sized for u32 { } + +struct Rc { } +impl Clone for Rc { } +impl Sized for Rc { } + +struct Box { } +impl AsRef for Box where T: Sized { } +impl Clone for Box where T: Clone { } +impl Sized for Box { } + +// Meant to be [T] +struct Slice where T: Sized { } +impl Sized for Slice { } +impl AsRef> for Slice where T: Sized { } + +struct Vec where T: Sized { } +impl AsRef> for Vec where T: Sized { } +impl AsRef> for Vec where T: Sized { } +impl Clone for Vec where T: Clone, T: Sized { } +impl Sized for Vec where T: Sized { } + +trait SliceExt + where ::Item: Clone +{ + type Item; +} + +impl SliceExt for Slice + where T: Clone +{ + type Item = T; +} +"; + +const CYCLEY_GOAL: &str = " +forall { + if ( + as SliceExt>::Item: Clone; + as SliceExt>::Item: Sized; + T: Clone; + T: Sized + ) { + T: Sized + } +} +"; + +#[bench] +fn cycley_slg(b: &mut Bencher) { + run_bench( + CYCLEY, + SolverChoice::SLG { max_size: 20 }, + CYCLEY_GOAL, + b, + "Unique", + ); +} -- cgit v1.2.3