File indexing completed on 2024-04-06 12:13:14
0001
0002 #include "FWCore/Utilities/interface/HRRealTime.h"
0003
0004 #include <ctime>
0005 #include <cmath>
0006 #include <typeinfo>
0007 #include <iostream>
0008
0009 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>
0010 #include <cppunit/extensions/HelperMacros.h>
0011
0012 namespace {
0013
0014 double gcrap = 0;
0015 void waiste() {
0016 for (double i = 1; i < 100000; i++)
0017 gcrap += std::log(std::sqrt(i));
0018 }
0019 }
0020
0021
0022
0023 class TestTimers : public CppUnit::TestFixture {
0024 CPPUNIT_TEST_SUITE(TestTimers);
0025 CPPUNIT_TEST(check_stdclock);
0026 CPPUNIT_TEST(check_RealTime);
0027 CPPUNIT_TEST_SUITE_END();
0028
0029 public:
0030 void setUp() {}
0031 void tearDown() {}
0032 void check_stdclock();
0033 void check_RealTime();
0034 };
0035
0036 CPPUNIT_TEST_SUITE_REGISTRATION(TestTimers);
0037
0038 template <typename S>
0039 void checkTime(S source, bool hr) {
0040
0041
0042 typedef edm::HRTimeDiffType T;
0043
0044 T i = source();
0045
0046 CPPUNIT_ASSERT(!(i < 0));
0047
0048
0049
0050 waiste();
0051
0052 T a = source();
0053 T b = source();
0054 CPPUNIT_ASSERT(!((a - i) < 0));
0055 CPPUNIT_ASSERT(!((b - a) < 0));
0056 if (hr)
0057 CPPUNIT_ASSERT(a > i);
0058
0059 waiste();
0060
0061 T c = source();
0062 double d = double(source() - c);
0063 CPPUNIT_ASSERT(!(d < 0));
0064
0065 T e = source();
0066 CPPUNIT_ASSERT(!((c - i) < (b - i)));
0067 CPPUNIT_ASSERT(!((e - i) < (c - i)));
0068 if (hr)
0069 CPPUNIT_ASSERT((e - i) > (b - i));
0070 }
0071
0072 #define CHECKTIME(S, HR) \
0073 std::cout << "checking source " << #S << std::endl; \
0074 checkTime(&S, HR)
0075
0076 void TestTimers::check_stdclock() { CHECKTIME(std::clock, false); }
0077
0078 void TestTimers::check_RealTime() { CHECKTIME(edm::hrRealTime, true); }