GCC Code Coverage Report


Directory: ./
File: benchmarks/serialization_frequency.cpp
Date: 2022-06-30 06:29:57
Exec Total Coverage
Lines: 0 19 0.0%
Branches: 0 24 0.0%

Line Branch Exec Source
1 #include <chrono>
2 #include "shared_memory/demos/four_int_values.hpp"
3 #include "shared_memory/serializer.hpp"
4
5 // checks at which frequency 1 million items can be serialized
6
7 void execute()
8 {
9 int nb_iterations = 1000000; // 1 million
10
11 shared_memory::Four_int_values fiv(1, 1, 1, 1);
12
13 shared_memory::Serializer<shared_memory::Four_int_values> serializer;
14 long int total_size_=0;
15
16 auto start = std::chrono::steady_clock::now();
17
18 for (int iteration = 0; iteration < nb_iterations; iteration++)
19 {
20 const std::string& serialized = serializer.serialize(fiv);
21 // just to make sure the compiler does not remove the line
22 // above for optimization purposes
23 total_size_ += serialized.size();
24 }
25
26 auto end = std::chrono::steady_clock::now();
27
28 long int duration_us =
29 std::chrono::duration_cast<std::chrono::microseconds>(end - start)
30 .count();
31 double duration_seconds = static_cast<double>(duration_us) / 1e6;
32
33 double frequency = static_cast<double>(nb_iterations) / duration_seconds;
34
35 std::cout << "\nserialization frequency: " << frequency
36 << " | irrelevant data: " << total_size_ << "\n\n";
37 }
38
39 int main()
40 {
41 execute();
42 return 0;
43 }
44