1- use codspeed:: codspeed:: { black_box, CodSpeed , WARMUP_RUNS } ;
1+ use codspeed:: {
2+ codspeed:: { black_box, CodSpeed , WARMUP_RUNS } ,
3+ utils:: { get_formated_function_path, get_git_relative_path} ,
4+ } ;
25
36pub struct Bencher {
47 pub bytes : u64 ,
58 codspeed : CodSpeed ,
6- current_uri : String ,
9+ current_file : String ,
10+ current_bench_path : String ,
711}
812
913impl Bencher {
10- pub fn set_current_uri ( & mut self , uri : String ) {
11- self . current_uri = uri;
14+ pub fn set_current_file ( & mut self , file : impl Into < String > ) {
15+ self . current_file = file. into ( ) ;
16+ }
17+
18+ pub fn set_current_bench_path ( & mut self , bench : impl Into < String > ) {
19+ self . current_bench_path = bench. into ( ) ;
1220 }
1321
1422 pub fn push_group ( & mut self , group : & str ) {
@@ -23,11 +31,13 @@ impl Bencher {
2331 where
2432 F : FnMut ( ) -> T ,
2533 {
26- let uri = self . current_uri . as_str ( ) ;
34+ let file = get_git_relative_path ( self . current_file . as_str ( ) ) ;
35+ let bench_path = get_formated_function_path ( self . current_bench_path . as_str ( ) ) ;
36+ let uri = format ! ( "{}::{}" , file. to_string_lossy( ) , bench_path) ;
2737 for _ in 0 ..WARMUP_RUNS {
2838 black_box ( inner ( ) ) ;
2939 }
30- self . codspeed . start_benchmark ( uri) ;
40+ self . codspeed . start_benchmark ( uri. as_str ( ) ) ;
3141 black_box ( inner ( ) ) ;
3242 self . codspeed . end_benchmark ( ) ;
3343 }
@@ -42,18 +52,20 @@ impl Default for Bencher {
4252 Bencher {
4353 bytes : 0 ,
4454 codspeed : CodSpeed :: new ( ) ,
45- current_uri : String :: new ( ) ,
55+ current_file : String :: new ( ) ,
56+ current_bench_path : String :: new ( ) ,
4657 }
4758 }
4859}
4960
5061#[ macro_export]
5162macro_rules! benchmark_group {
52- ( $group_name: ident, $( $function: path) ,+) => {
63+ ( $group_name: ident, $( $function: path ) ,+ $ ( , ) * ) => {
5364 pub fn $group_name( bencher: & mut $crate:: Bencher ) {
5465 bencher. push_group( stringify!( $group_name) ) ;
5566 $(
56- bencher. set_current_uri( $crate:: codspeed_uri!( $function) ) ;
67+ bencher. set_current_file( codspeed:: abs_file!( ) ) ;
68+ bencher. set_current_bench_path( stringify!( $function) ) ;
5769 $function( bencher) ;
5870 ) +
5971 bencher. pop_group( ) ;
0 commit comments