-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
example_csv.cpp
52 lines (44 loc) · 1.3 KB
/
example_csv.cpp
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
#include <nanobench.h>
#include <thirdparty/doctest/doctest.h>
#include <deque>
#include <iostream>
#include <list>
#include <vector>
namespace {
template <typename ContainerT>
void testBenchSet(char const* label, int n, ankerl::nanobench::Bench& bench) {
bench.run(label, [&] {
ContainerT items;
for (int i = 0; i < n; ++i) {
// NOLINTNEXTLINE(performance-inefficient-vector-operation)
items.push_back(i);
}
ankerl::nanobench::doNotOptimizeAway(&items);
});
}
void exampleCsv(bool useCsv) {
ankerl::nanobench::Bench bench;
if (useCsv) {
bench.output(nullptr);
}
for (int n = 100; n <= 10000; n *= 10) {
bench.title("Size " + std::to_string(n));
testBenchSet<std::vector<int>>("std::vector<int>", n, bench);
testBenchSet<std::deque<int>>("std::deque<int>", n, bench);
testBenchSet<std::list<int>>("std::list<int>", n, bench);
if (useCsv) {
// could also use ankerl::nanobench::templates::csv() which contains
// a header
bench.render(ankerl::nanobench::templates::csv(), std::cout);
}
}
}
} // namespace
// NOLINTNEXTLINE
TEST_CASE("example_csv_csv") {
exampleCsv(true);
}
// NOLINTNEXTLINE
TEST_CASE("example_csv_md") {
exampleCsv(false);
}