Skip to content

Commit

Permalink
[tests] Added SleeptoAccuracy (disabled)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed May 28, 2019
1 parent 444d40f commit b3aa812
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/filelist.maf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SOURCES
test_buffer.cpp
test_connection_timeout.cpp
test_epoll.cpp
test_seqno.cpp
test_strict_encription.cpp
test_epoll.cpp
test_timer.cpp
47 changes: 47 additions & 0 deletions test/test_timer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "gtest/gtest.h"
#include <chrono>
#include <thread>
#include <array>
#include <numeric> // std::accumulate
#include "common.h"




TEST(CTimer, DISABLED_SleeptoAccuracy)
{
using namespace std;

const int num_samples = 1000;
array<uint64_t, num_samples> sleeps_us;

const uint64_t freq = CTimer::getCPUFrequency();
std::cerr << "CPU Frequency: " << freq << "\n";

const uint64_t sleep_intervals_us[] = { 1, 5, 10, 50, 100, 250, 500, 1000, 5000, 10000 };

CTimer timer;

for (uint64_t interval_us : sleep_intervals_us)
{
for (int i = 0; i < num_samples; i++)
{
uint64_t currtime;
CTimer::rdtsc(currtime);

timer.sleepto(currtime + interval_us * freq);

uint64_t new_time;
CTimer::rdtsc(new_time);
sleeps_us[i] = (new_time - currtime) / freq;
}

cerr << "Target sleep duration: " << interval_us << " us\n";
cerr << "avg sleep duration: " << accumulate(sleeps_us.begin(), sleeps_us.end(), (uint64_t) 0) / num_samples << " us\n";
cerr << "min sleep duration: " << *min_element(sleeps_us.begin(), sleeps_us.end()) << " us\n";
cerr << "max sleep duration: " << *max_element(sleeps_us.begin(), sleeps_us.end()) << " us\n";
cerr << "\n";
}
}


0 comments on commit b3aa812

Please sign in to comment.