1
1
#include " c_bench.h"
2
- #include " cnpy.h"
2
+ #include < cnpy.h>
3
+ #include < benchmark/benchmark.h>
3
4
#include < algorithm>
4
5
#include < cstdlib>
5
6
#include < iostream>
6
7
7
- #define N_REPEAT 20
8
-
9
- int main (int argc, char **argv) {
10
- (void )argc;
11
- (void )argv;
12
-
8
+ static void bm_lleaves (benchmark::State& state) {
13
9
char *model_name = std::getenv (" LLEAVES_BENCHMARK_MODEL" );
14
- std::cout << " Running model " << model_name << " \n " ;
15
10
16
11
std::ostringstream model_stream;
17
12
model_stream << " ../../data/" << model_name << " .npy" ;
18
13
std::string model_file = model_stream.str ();
19
14
cnpy::NpyArray arr = cnpy::npy_load (model_file);
20
15
21
- std::cout << " Batchsize: " << arr.shape [0 ] << " \n " ;
22
-
23
16
auto *loaded_data = arr.data <double >();
24
- ulong n_preds = arr.shape [0 ] / (ulong) 6 ;
17
+ ulong n_preds = arr.shape [0 ];
25
18
auto *out = (double *)(malloc (n_preds * sizeof (double )));
26
19
27
- std::array<double , N_REPEAT> timings{};
28
- clock_t start, end;
29
- std::cout << " starting...\n " ;
30
- for (size_t i = 0 ; i < N_REPEAT; ++i) {
31
- start = clock ();
32
- forest_root (loaded_data, out, (int )0 , (int )n_preds);
33
- end = clock ();
34
-
35
- timings[i] = (double )(end - start) / CLOCKS_PER_SEC;
20
+ for (auto _ : state){
21
+ // predict over the whole input array
22
+ forest_root (loaded_data, out, (int )0 , (int )n_preds);
36
23
}
37
- std::cout << " ...ending, took "
38
- << std::accumulate (timings.begin (), timings.end (), 0.0 ) << " \n " ;
39
-
40
- std::cout << " Runtime: " << *std::min_element (timings.begin (), timings.end ())
41
- << " \n " ;
42
24
}
25
+
26
+ BENCHMARK (bm_lleaves);
27
+ BENCHMARK_MAIN ();
0 commit comments