@@ -50,19 +50,16 @@ pub fn parse_exec_time(output: &str) -> f64 {
50
50
if !l. contains ( "elapsed:" ) {
51
51
acc
52
52
} else {
53
- let timing = l
54
- . split ( "(elapsed: " )
55
- . last ( )
56
- . unwrap ( ) ;
57
-
58
- // see [rust/library/core/src/time.rs](https://git.io/Jy1rI)
59
- if timing. ends_with ( "ns)" ) {
53
+ let timing = l. split ( "(elapsed: " ) . last ( ) . unwrap ( ) ;
54
+ // use `contains` istd. of `ends_with`: string may contain ANSI escape sequences.
55
+ // possible time formats: see [rust/library/core/src/time.rs](https://git.io/Jy1rI).
56
+ if timing. contains ( "ns)" ) {
60
57
acc // range below rounding precision.
61
- } else if timing. ends_with ( "µs)" ) {
58
+ } else if timing. contains ( "µs)" ) {
62
59
acc + parse_time ( timing, "µs" ) / 1000_f64
63
- } else if timing. ends_with ( "ms)" ) {
60
+ } else if timing. contains ( "ms)" ) {
64
61
acc + parse_time ( timing, "ms" )
65
- } else if timing. ends_with ( "s)" ) {
62
+ } else if timing. contains ( "s)" ) {
66
63
acc + parse_time ( timing, "s" ) * 1000_f64
67
64
} else {
68
65
acc
@@ -91,9 +88,10 @@ mod tests {
91
88
#[ test]
92
89
fn test_parse_exec_time ( ) {
93
90
assert_approx_eq ! (
94
- parse_exec_time(
95
- "🎄 Part 1 🎄\n 0 (elapsed: 74.13ns)\n 🎄 Part 2 🎄\n 0 (elapsed: 50.00ns)"
96
- ) ,
91
+ parse_exec_time( & format!(
92
+ "🎄 Part 1 🎄\n 0 (elapsed: 74.13ns){}\n 🎄 Part 2 🎄\n 0 (elapsed: 50.00ns){}" ,
93
+ ANSI_RESET , ANSI_RESET
94
+ ) ) ,
97
95
0_f64
98
96
) ;
99
97
0 commit comments