@@ -30,12 +30,11 @@ template<typename T>
30
30
struct isRigtorp : std::false_type {};
31
31
32
32
template <typename T>
33
- void bench (char const * name, int cpu1, int cpu2) {
33
+ auto bench (char const * name, long iters, int cpu1, int cpu2) {
34
+ using namespace std ::chrono_literals;
34
35
using value_type = typename T::value_type;
35
36
36
37
constexpr auto fifoSize = 131072 ;
37
- constexpr auto iters = 200'000'000l ;
38
- // constexpr auto iters = 100'000'000l;
39
38
40
39
T q (fifoSize);
41
40
auto t = std::jthread ([&] {
@@ -77,21 +76,28 @@ void bench(char const* name, int cpu1, int cpu2) {
77
76
;
78
77
}
79
78
auto stop = std::chrono::steady_clock::now ();
80
- auto delta = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
81
- std::cout << std::setw (7 ) << std::left << name << " : "
82
- << std::setw (10 ) << std::right << iters * 1'000'000'000 / delta.count ()
83
- << " ops/s\n " ;
79
+ auto delta = stop - start;
80
+ return (iters * 1s)/delta;
84
81
}
85
82
86
83
template <template <typename > class FifoT >
87
84
void bench (char const * name, int argc, char * argv[]) {
88
- int cpu1 = - 1 ;
89
- int cpu2 = - 1 ;
85
+ int cpu1 = 1 ;
86
+ int cpu2 = 2 ;
90
87
if (argc == 3 ) {
91
88
cpu1 = std::atoi (argv[1 ]);
92
89
cpu2 = std::atoi (argv[2 ]);
93
90
}
94
- // using value_type = std::array<long, 25>;
91
+
92
+ constexpr auto iters = 400'000'000l ;
93
+ // constexpr auto iters = 100'000'000l;
94
+
95
95
using value_type = std::int64_t ;
96
- bench<FifoT<value_type>>(name, cpu1, cpu2);
96
+
97
+ // warmup
98
+ bench<FifoT<value_type>>(name, 1'000'000 , cpu1, cpu2);
99
+
100
+ auto opsPerSec = bench<FifoT<value_type>>(name, iters, cpu1, cpu2);
101
+ std::cout << std::setw (7 ) << std::left << name << " : "
102
+ << std::setw (10 ) << std::right << opsPerSec << " ops/s\n " ;
97
103
}
0 commit comments