Agora
1.2.0
Agora project
|
Go to the documentation of this file.
9 static inline size_t rdtsc() {
12 asm volatile(
"rdtsc" :
"=a"(rax),
"=d"(rdx));
13 return static_cast<size_t>((rdx << 32) | rax);
22 size_t upp =
static_cast<size_t>(
freq_ghz * ns);
28 clock_gettime(CLOCK_REALTIME, &
start);
29 uint64_t rdtsc_start =
rdtsc();
34 for (uint64_t
i = 0;
i < 1000000;
i++) {
35 sum +=
i + (sum +
i) * (
i % sum);
38 if (sum != 13580802877818827968ull) {
42 clock_gettime(CLOCK_REALTIME, &
end);
44 static_cast<uint64_t
>(
end.tv_sec -
start.tv_sec) * 1000000000 +
45 static_cast<uint64_t
>(
end.tv_nsec -
start.tv_nsec);
46 uint64_t rdtsc_cycles =
rdtsc() - rdtsc_start;
48 double _freq_ghz = rdtsc_cycles * 1.0 / clock_ns;
54 return (cycles / (
freq_ghz * 1000000000));
59 return (cycles / (
freq_ghz * 1000000));
68 return static_cast<size_t>(us * 1000 *
freq_ghz);
72 return static_cast<size_t>(ns *
freq_ghz);
81 static double sec_since(
const struct timespec& t0) {
83 clock_gettime(CLOCK_REALTIME, &t1);
84 return (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1000000000.0;
88 static double ns_since(
const struct timespec& t0) {
90 clock_gettime(CLOCK_REALTIME, &t1);
91 return (t1.tv_sec - t0.tv_sec) * 1000000000.0 + (t1.tv_nsec - t0.tv_nsec);
94 static double stddev(
const std::vector<double> in_vec) {
95 if (in_vec.size() == 0)
return 0.0;
96 double sum = std::accumulate(in_vec.begin(), in_vec.end(), 0.0);
97 double mean = sum * 1.0 / in_vec.size();
99 std::inner_product(in_vec.begin(), in_vec.end(), in_vec.begin(), 0.0);
103 static double mean(
const std::vector<double> in_vec) {
104 if (in_vec.empty())
return 0.0;
105 double sum = std::accumulate(in_vec.begin(), in_vec.end(), 0.0);
106 return sum * 1.0 / in_vec.size();
static double to_nsec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to nsec.
Definition: timer.h:76
double freq_ghz
Definition: bench.cc:10
static size_t rdtsc()
Return the TSC.
Definition: timer.h:9
std::vector< double > ms_duration_vec
Definition: timer.h:114
double stddev_msec()
Definition: timer.h:126
static double mean(const std::vector< double > in_vec)
Definition: timer.h:103
static const auto & dpath_rdtsc
An alias for rdtsc() to distinguish calls on the critical path.
Definition: timer.h:17
double avg_msec()
Definition: timer.h:127
static size_t us_to_cycles(double us, double freq_ghz)
Definition: timer.h:67
void start()
Definition: timer.h:120
static void nano_sleep(size_t ns, double freq_ghz)
Definition: timer.h:19
static double to_usec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to usec.
Definition: timer.h:63
size_t start_tsc
Definition: timer.h:112
void stop()
Definition: timer.h:121
for i
Definition: generate_data.m:107
static double stddev(const std::vector< double > in_vec)
Definition: timer.h:94
static double ns_since(const struct timespec &t0)
Return nanoseconds elapsed since timestamp t0.
Definition: timer.h:88
end start
Definition: inspect_agora_results.m:95
TscTimer(size_t n_timestamps, double freq_ghz)
Definition: timer.h:116
double avg_usec()
Definition: timer.h:128
double freq_ghz
Definition: timer.h:113
static size_t ns_to_cycles(double ns, double freq_ghz)
Definition: timer.h:71
static double to_sec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to seconds.
Definition: timer.h:53
void reset()
Definition: timer.h:125
Simple time that uses RDTSC.
Definition: timer.h:110
static double measure_rdtsc_freq()
Definition: timer.h:26
static double to_msec(size_t cycles, double freq_ghz)
Convert cycles measured by rdtsc with frequence freq_ghz to msec.
Definition: timer.h:58
static double sec_since(const struct timespec &t0)
Return seconds elapsed since timestamp t0.
Definition: timer.h:81