@@ -30,12 +30,11 @@ template<typename T>
3030struct isRigtorp : std::false_type {};
3131
3232template <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;
3435 using value_type = typename T::value_type;
3536
3637 constexpr auto fifoSize = 131072 ;
37- constexpr auto iters = 200'000'000l ;
38- // constexpr auto iters = 100'000'000l;
3938
4039 T q (fifoSize);
4140 auto t = std::jthread ([&] {
@@ -77,21 +76,28 @@ void bench(char const* name, int cpu1, int cpu2) {
7776 ;
7877 }
7978 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;
8481}
8582
8683template <template <typename > class FifoT >
8784void bench (char const * name, int argc, char * argv[]) {
88- int cpu1 = - 1 ;
89- int cpu2 = - 1 ;
85+ int cpu1 = 1 ;
86+ int cpu2 = 2 ;
9087 if (argc == 3 ) {
9188 cpu1 = std::atoi (argv[1 ]);
9289 cpu2 = std::atoi (argv[2 ]);
9390 }
94- // using value_type = std::array<long, 25>;
91+
92+ constexpr auto iters = 400'000'000l ;
93+ // constexpr auto iters = 100'000'000l;
94+
9595 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 " ;
97103}
0 commit comments