1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#![feature(try_from)]
#![feature(test)]
#![allow(dead_code)]
extern crate byteorder;
extern crate chrono;
extern crate failure;
extern crate test;
pub(crate) mod bits;
pub(crate) mod dyncrc16;
pub mod error;
pub mod profile;
pub mod types;
pub use types::{
file::{
self,
File,
},
record,
};
pub use profile::messages;
#[cfg(test)]
mod tests {
use std::{
fs::File,
io::{
Cursor,
Read,
},
path::Path,
};
use test::Bencher;
fn bench_file_decoding(b: &mut Bencher, file: &Path) {
let mut file = File::open(file).unwrap();
let data = {
let mut bytes = Vec::new();
file.read_to_end(&mut bytes).unwrap();
Cursor::new(bytes)
};
b.iter(|| super::File::decode(&mut data.clone()).unwrap());
}
macro_rules! bench_file {
($name:ident, $path:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
bench_file_decoding(
b,
&Path::new(env!("CARGO_MANIFEST_DIR")).join($path),
);
}
};
}
bench_file!(bench_python_fitparse_1, "testdata/python_fitparse_1.fit");
bench_file!(bench_python_fitparse_2, "testdata/python_fitparse_2.fit");
}