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
+ } ;
2
5
3
6
pub struct Bencher {
4
7
pub bytes : u64 ,
5
8
codspeed : CodSpeed ,
6
- current_uri : String ,
9
+ current_file : String ,
10
+ current_bench_path : String ,
7
11
}
8
12
9
13
impl 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 ( ) ;
12
20
}
13
21
14
22
pub fn push_group ( & mut self , group : & str ) {
@@ -23,11 +31,13 @@ impl Bencher {
23
31
where
24
32
F : FnMut ( ) -> T ,
25
33
{
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) ;
27
37
for _ in 0 ..WARMUP_RUNS {
28
38
black_box ( inner ( ) ) ;
29
39
}
30
- self . codspeed . start_benchmark ( uri) ;
40
+ self . codspeed . start_benchmark ( uri. as_str ( ) ) ;
31
41
black_box ( inner ( ) ) ;
32
42
self . codspeed . end_benchmark ( ) ;
33
43
}
@@ -42,18 +52,20 @@ impl Default for Bencher {
42
52
Bencher {
43
53
bytes : 0 ,
44
54
codspeed : CodSpeed :: new ( ) ,
45
- current_uri : String :: new ( ) ,
55
+ current_file : String :: new ( ) ,
56
+ current_bench_path : String :: new ( ) ,
46
57
}
47
58
}
48
59
}
49
60
50
61
#[ macro_export]
51
62
macro_rules! benchmark_group {
52
- ( $group_name: ident, $( $function: path) ,+) => {
63
+ ( $group_name: ident, $( $function: path ) ,+ $ ( , ) * ) => {
53
64
pub fn $group_name( bencher: & mut $crate:: Bencher ) {
54
65
bencher. push_group( stringify!( $group_name) ) ;
55
66
$(
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) ) ;
57
69
$function( bencher) ;
58
70
) +
59
71
bencher. pop_group( ) ;
0 commit comments