@@ -311,21 +311,9 @@ impl Divan {
311311 if should_compute_stats {
312312 let stats = bench_context. compute_stats ( ) ;
313313 {
314- // WARNING: Keep in sync with `codspeed-divan-compat::uri::generate`
315- // Not worth doing the work of actually using the same code since this fork
316- // is temporary
317- let name = bench_entry. display_name ( ) . to_string ( ) ;
318- let file = bench_entry. meta ( ) . location . file ;
319- let mut module_path = bench_entry
320- . meta ( )
321- . module_path_components ( )
322- . skip ( 1 )
323- . collect :: < Vec < _ > > ( )
324- . join ( "::" ) ;
325- if !module_path. is_empty ( ) {
326- module_path. push_str ( "::" ) ;
327- }
328- let uri = format ! ( "{file}::{module_path}{name}" ) ;
314+ let CodspeedBench { bench_name, uri } =
315+ generate_codspeed_bench_name ( & bench_entry, bench_display_name) ;
316+
329317 let iter_per_round = bench_context. samples . sample_size ;
330318 let times_ns: Vec < _ > = bench_context
331319 . samples
@@ -336,7 +324,7 @@ impl Divan {
336324 let max_time_ns = options. max_time . map ( |t| t. as_nanos ( ) ) ;
337325 :: codspeed:: walltime:: collect_raw_walltime_results (
338326 "divan" ,
339- name ,
327+ bench_name ,
340328 uri,
341329 iter_per_round,
342330 max_time_ns,
@@ -383,6 +371,76 @@ impl Divan {
383371 }
384372}
385373
374+ struct CodspeedBench {
375+ bench_name : String ,
376+ uri : String ,
377+ }
378+
379+ /// Generates a Codspeed benchmark name and URI
380+ ///
381+ /// WARNING: Keep in sync with `codspeed-divan-compat::uri::generate`
382+ /// Not worth doing the work of actually using the same code since this fork
383+ /// is temporary
384+ fn generate_codspeed_bench_name (
385+ bench_entry : & AnyBenchEntry ,
386+ closure_bench_display_name : & str ,
387+ ) -> CodspeedBench {
388+ let bench_function_name = bench_entry. meta ( ) . display_name ;
389+
390+ let ( bench_type_name, bench_arg_name) = {
391+ let bench_function_or_type_name = bench_entry. display_name ( ) . to_string ( ) ;
392+
393+ let type_name = if bench_function_or_type_name == bench_function_name {
394+ None
395+ } else {
396+ Some ( bench_function_or_type_name)
397+ } ;
398+
399+ let arg_name = match type_name. as_ref ( ) {
400+ None => {
401+ if closure_bench_display_name == bench_function_name {
402+ None
403+ } else {
404+ Some ( closure_bench_display_name)
405+ }
406+ }
407+ Some ( type_name) => {
408+ if closure_bench_display_name == type_name {
409+ None
410+ } else {
411+ Some ( closure_bench_display_name)
412+ }
413+ }
414+ } ;
415+
416+ ( type_name, arg_name)
417+ } ;
418+
419+ let mut bench_name = bench_function_name. to_string ( ) ;
420+
421+ match ( bench_type_name, bench_arg_name) {
422+ ( None , None ) => { }
423+ ( Some ( type_name) , None ) => {
424+ bench_name. push_str ( format ! ( "[{type_name}]" ) . as_str ( ) ) ;
425+ }
426+ ( None , Some ( arg_name) ) => {
427+ bench_name. push_str ( format ! ( "[{arg_name}]" ) . as_str ( ) ) ;
428+ }
429+ ( Some ( type_name) , Some ( arg_name) ) => {
430+ bench_name. push_str ( format ! ( "[{type_name}, {arg_name}]" ) . as_str ( ) ) ;
431+ }
432+ }
433+
434+ let file = bench_entry. meta ( ) . location . file ;
435+ let mut module_path =
436+ bench_entry. meta ( ) . module_path_components ( ) . skip ( 1 ) . collect :: < Vec < _ > > ( ) . join ( "::" ) ;
437+ if !module_path. is_empty ( ) {
438+ module_path. push_str ( "::" ) ;
439+ }
440+ let uri = format ! ( "{file}::{module_path}{bench_name}" ) ;
441+ CodspeedBench { bench_name, uri }
442+ }
443+
386444/// Makes `Divan::skip_regex` input polymorphic.
387445pub trait SkipRegex {
388446 fn skip_regex ( self , divan : & mut Divan ) ;
0 commit comments