Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 04d16d0

Browse files
authored
Merge pull request #1070 from JanDorniak99/fix_radix_benchmark
add readme to benchmarks and fix dividing by zero in radix bench
2 parents efa2413 + 88d4245 commit 04d16d0

4 files changed

Lines changed: 67 additions & 7 deletions

File tree

benchmarks/concurrent_hash_map/insert_open.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2020, Intel Corporation */
2+
/* Copyright 2020-2021, Intel Corporation */
33

44
/*
5-
* insert_open.cpp -- this simple benchmarks is used to measure time of
5+
* insert_open.cpp -- this simple benchmark is used to measure time of
66
* inserting specified number of elements and time of runtime_initialize().
77
*/
88

benchmarks/radix/radix_tree.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ print_time_per_element(std::string msg,
5151
std::chrono::nanoseconds::rep total_time,
5252
size_t n_elements)
5353
{
54+
if (n_elements == 0) {
55+
throw std::invalid_argument(
56+
"Benchmark failed, wrong params passed.");
57+
}
58+
5459
std::cout << msg << static_cast<size_t>(total_time) / n_elements << "ns"
5560
<< std::endl;
5661
}
@@ -200,12 +205,28 @@ main(int argc, char *argv[])
200205
}
201206

202207
const char *path = argv[1];
203-
if (argc > 2)
208+
if (argc > 2) {
204209
params.count = std::stoul(argv[2]);
205-
if (argc > 3)
210+
if (params.count == 0) {
211+
std::cerr << "Number of the elements must be > 0"
212+
<< std::endl;
213+
return 1;
214+
}
215+
}
216+
if (argc > 3) {
206217
params.batch_size = std::stoul(argv[3]);
207-
if (argc > 4)
218+
if (params.batch_size == 0) {
219+
std::cerr << "Batch size must be > 0" << std::endl;
220+
return 1;
221+
}
222+
}
223+
if (argc > 4) {
208224
params.sample_size = std::stoul(argv[4]);
225+
if (params.sample_size == 0) {
226+
std::cerr << "Sample size must be > 0" << std::endl;
227+
return 1;
228+
}
229+
}
209230

210231
std::cout << "Radix benchmark, count: " << params.count
211232
<< ", batch_size: " << params.batch_size

benchmarks/readme.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Benchmarks
2+
3+
These benchmarks allow measuring some operations in the libpmemobj-cpp.
4+
5+
Currently following benchmarks are available:
6+
- **concurrent_hash_map_insert_open**: this benchmark is used to measure time of inserting specified number of elements and time of `runtime_initialize()` in concurrent hash map.
7+
- **radix_tree**: this benchmark is used to compare times of basic operations in radix_tree and std::map.
8+
- **self_relative_pointer_assignment**: this benchmark is used to measure time of the assignment operator and the swap function for persistent_ptr and self_relative_ptr.
9+
- **self_relative_pointer_get**: this benchmark is used to measure time of accessing and changing a specified number of elements from a persistent array using self_relative_ptr and persistent_ptr.
10+
11+
## Compiling
12+
13+
Follow build steps for your OS (as described in top-level README), just make sure that the BUILD_BENCHMARKS option is ON.
14+
15+
To build all benchmarks (when you are in a build dir):
16+
```sh
17+
$ cd benchmarks
18+
$ make
19+
```
20+
21+
To build a certain benchmark (when you are in a build dir):
22+
```sh
23+
$ cd benchmarks
24+
$ make benchmark-<name_of_benchmark>
25+
```
26+
27+
## Running
28+
29+
**Warning:**
30+
>These benchmarks shouldn't be run in a production environment, because they can remove/modify existing data in the tested containers.
31+
32+
Each benchmark can require various input parameters. If you want to see the usage of a certain benchmark, just run this benchmark's binary without any parameters, e.g.
33+
```sh
34+
$ ./benchmark-radix_tree
35+
```
36+
For example radix_tree benchmark needs following parameters: file_name \[count] \[batch_size] \[sample_size]. Example execution:
37+
```sh
38+
$ ./benchmark-radix_tree my_pool 20000 200 2000
39+
```

benchmarks/self_relative_pointer/assignment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2020, Intel Corporation */
2+
/* Copyright 2020-2021, Intel Corporation */
33

44
/*
5-
* assignment.cpp -- this benchmarks is used to measure time of
5+
* assignment.cpp -- this benchmark is used to measure time of
66
* the assignment operator and the swap function for persistent_ptr and
77
* self_relative_ptr
88
*/

0 commit comments

Comments
 (0)