Commit 7cbc9e34 authored by Laurentiu Nicola's avatar Laurentiu Nicola

ENH: Enable otb::Stopwatch tests

parent fa12766d
......@@ -20,18 +20,17 @@
#include <cassert>
#include <chrono>
#include <iostream>
#include <cstdlib>
#if 0
#include <unistd.h>
#include "itkTimeProbe.h"
#endif
#include <thread>
#include "itkMacro.h"
#include "otbStopwatch.h"
using namespace std::chrono_literals;
int otbStopwatchTest(int itkNotUsed(argc), char * itkNotUsed(argv)[])
{
otb::Stopwatch sw;
......@@ -51,42 +50,21 @@ int otbStopwatchTest(int itkNotUsed(argc), char * itkNotUsed(argv)[])
assert( sw.IsRunning() );
sw.Stop();
#if 0
// We have no portable sleep() and otbThreads is not linked here
sw.Start();
usleep(500 * 1000);
std::this_thread::sleep_for(500ms);
sw.Stop();
assert( sw.GetElapsedMilliseconds() > 450 && sw.GetElapsedMilliseconds() < 550 );
sw.Start();
usleep(500 * 1000);
std::this_thread::sleep_for(500ms);
sw.Stop();
assert( sw.GetElapsedMilliseconds() > 900 && sw.GetElapsedMilliseconds() < 1100 );
sw.Restart();
usleep(500 * 1000);
std::this_thread::sleep_for(500ms);
sw.Stop();
assert( sw.GetElapsedMilliseconds() > 450 && sw.GetElapsedMilliseconds() < 550 );
const int iterations = 100000;
sw.Restart();
for (int i = 0; i < iterations; i++)
{
itk::TimeProbe chrono;
chrono.Start();
chrono.Stop();
}
std::cerr << "itk::TimeProbe time: " << sw.GetElapsedMilliseconds() << std::endl;
sw.Restart();
for (int i = 0; i < iterations; i++)
{
auto chrono = otb::Stopwatch::StartNew();
chrono.Stop();
}
std::cerr << "otb::Stopwatch time: " << sw.GetElapsedMilliseconds() << std::endl;
#endif
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment