| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* @file benchmark_common.hh |
| 3 |
|
|
* @author Vincent Berenz |
| 4 |
|
|
* @license License BSD-3-Clause |
| 5 |
|
|
* @copyright Copyright (c) 2019, New York University and Max Planck |
| 6 |
|
|
* Gesellschaft. |
| 7 |
|
|
* @date 2019-05-22 |
| 8 |
|
|
* |
| 9 |
|
|
* @brief Common tools for benchmarking |
| 10 |
|
|
*/ |
| 11 |
|
|
#ifndef BENCHMARK_COMMON_HH |
| 12 |
|
|
#define BENCHMARK_COMMON_HH |
| 13 |
|
|
|
| 14 |
|
|
#include <signal.h> |
| 15 |
|
|
#include <unistd.h> |
| 16 |
|
|
#include <chrono> |
| 17 |
|
|
#include <cmath> |
| 18 |
|
|
#include <iostream> |
| 19 |
|
|
#include <vector> |
| 20 |
|
|
|
| 21 |
|
|
#define SHARED_MEMORY_SIZE 65536 |
| 22 |
|
|
#define SIZE 1000 |
| 23 |
|
|
#define NUMBER_OR_MEASURED_ITERATIONS 1000 |
| 24 |
|
|
#define MAX_NUNMBER_OF_ITERATION 10000 |
| 25 |
|
|
|
| 26 |
|
|
typedef std::chrono::high_resolution_clock::time_point TimeType; |
| 27 |
|
|
|
| 28 |
|
✗ |
static std::vector<double> DATA(SIZE, 2); |
| 29 |
|
|
bool RUNNING; |
| 30 |
|
✗ |
static std::string SHM_NAME("stress_test"); |
| 31 |
|
✗ |
static std::string SHM_OBJECT_NAME("stress_object"); |
| 32 |
|
|
|
| 33 |
|
|
struct MeasureTime |
| 34 |
|
|
{ |
| 35 |
|
✗ |
MeasureTime() |
| 36 |
|
|
{ |
| 37 |
|
✗ |
start(); |
| 38 |
|
|
} |
| 39 |
|
✗ |
void start() |
| 40 |
|
|
{ |
| 41 |
|
✗ |
tic_ = std::chrono::high_resolution_clock::now(); |
| 42 |
|
|
} |
| 43 |
|
✗ |
void update() |
| 44 |
|
|
{ |
| 45 |
|
✗ |
auto nanos = std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 46 |
|
✗ |
tic_ - prev_tic_) |
| 47 |
|
✗ |
.count(); |
| 48 |
|
✗ |
frequency_ = 1000.0 / (pow(10.0, -9.0) * nanos); |
| 49 |
|
✗ |
period_ = 1.0 / frequency_; |
| 50 |
|
✗ |
prev_tic_ = tic_; |
| 51 |
|
✗ |
tic_ = std::chrono::high_resolution_clock::now(); |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
|
friend std::ostream& operator<<(std::ostream& os, const MeasureTime& dt); |
| 55 |
|
|
|
| 56 |
|
|
TimeType tic_; |
| 57 |
|
|
TimeType prev_tic_; |
| 58 |
|
|
double frequency_; |
| 59 |
|
|
double period_; |
| 60 |
|
|
}; |
| 61 |
|
|
|
| 62 |
|
✗ |
std::ostream& operator<<(std::ostream& os, const MeasureTime& time) |
| 63 |
|
|
{ |
| 64 |
|
✗ |
os << "Frequency = " << time.frequency_ << " ; " |
| 65 |
|
✗ |
<< "Period = " << time.period_; |
| 66 |
|
✗ |
return os; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
|
void init_benchmark(); |
| 70 |
|
|
|
| 71 |
|
|
void code_to_benchamrk(); |
| 72 |
|
|
|
| 73 |
|
|
void end_benchmark(); |
| 74 |
|
|
|
| 75 |
|
|
#endif // BENCHMARK_COMMON_HH |
| 76 |
|
|
|