@@ -40,6 +40,8 @@ pub struct CheckCtx {
4040 /// Source of truth for tests.
4141 pub basis : CheckBasis ,
4242 pub gen_kind : GeneratorKind ,
43+ /// If specified, this value will override the value returned by [`iteration_count`].
44+ pub override_iterations : Option < u64 > ,
4345}
4446
4547impl CheckCtx {
@@ -53,6 +55,7 @@ impl CheckCtx {
5355 base_name_str : fn_ident. base_name ( ) . as_str ( ) ,
5456 basis,
5557 gen_kind,
58+ override_iterations : None ,
5659 } ;
5760 ret. ulp = crate :: default_ulp ( & ret) ;
5861 ret
@@ -62,6 +65,10 @@ impl CheckCtx {
6265 pub fn input_count ( & self ) -> usize {
6366 self . fn_ident . math_op ( ) . rust_sig . args . len ( )
6467 }
68+
69+ pub fn override_iterations ( & mut self , count : u64 ) {
70+ self . override_iterations = Some ( count)
71+ }
6572}
6673
6774/// Possible items to test against
@@ -71,6 +78,8 @@ pub enum CheckBasis {
7178 Musl ,
7279 /// Check against infinite precision (MPFR).
7380 Mpfr ,
81+ /// Benchmarks or other times when this is not relevant.
82+ None ,
7483}
7584
7685/// The different kinds of generators that provide test input, which account for input pattern
@@ -216,13 +225,20 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
216225 total_iterations = 800 ;
217226 }
218227
228+ let mut overridden = false ;
229+ if let Some ( count) = ctx. override_iterations {
230+ total_iterations = count;
231+ overridden = true ;
232+ }
233+
219234 // Adjust for the number of inputs
220235 let ntests = match t_env. input_count {
221236 1 => total_iterations,
222237 2 => ( total_iterations as f64 ) . sqrt ( ) . ceil ( ) as u64 ,
223238 3 => ( total_iterations as f64 ) . cbrt ( ) . ceil ( ) as u64 ,
224239 _ => panic ! ( "test has more than three arguments" ) ,
225240 } ;
241+
226242 let total = ntests. pow ( t_env. input_count . try_into ( ) . unwrap ( ) ) ;
227243
228244 let seed_msg = match ctx. gen_kind {
@@ -235,12 +251,13 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
235251
236252 test_log ( & format ! (
237253 "{gen_kind:?} {basis:?} {fn_ident} arg {arg}/{args}: {ntests} iterations \
238- ({total} total){seed_msg}",
254+ ({total} total){seed_msg}{omsg} ",
239255 gen_kind = ctx. gen_kind,
240256 basis = ctx. basis,
241257 fn_ident = ctx. fn_ident,
242258 arg = argnum + 1 ,
243259 args = t_env. input_count,
260+ omsg = if overridden { " (overridden)" } else { "" }
244261 ) ) ;
245262
246263 ntests
0 commit comments