52 const uint NUM_ELMS_PERFORMANCE_TEST = 50000000;
53 const uint NUMBER_LIMIT = 1 << 30;
55 typedef std::vector<int> VecI;
58 buildTestNumberz (uint cnt)
61 for (uint i=0; i<cnt; ++i)
63 int someNumber (rand() % (2*NUMBER_LIMIT) -NUMBER_LIMIT);
64 if (!someNumber) someNumber -=(1 +rand() % NUMBER_LIMIT);
66 data.push_back (someNumber);
88 ldiv_t res = ldiv(num,den);
89 return (0 >= res.quot && res.rem)? res.quot-1
121 verifyIntegerTypes<int>();
122 verifyIntegerTypes<long>();
123 verifyIntegerTypes<short>();
124 verifyIntegerTypes<int64_t>();
125 verifyIntegerTypes<long long int>();
165 verifyIntegerTypes ()
169 for (
int i=-12; i <= 12; ++i)
174 CHECK (
floordiv(n,d) == expectedRes);
218 VecI testdata = buildTestNumberz (2*NUM_ELMS_PERFORMANCE_TEST);
219 typedef VecI::const_iterator I;
221 clock_t start(0), stop(0);
222 _Fmt resultDisplay{
"timings(%s)%|30T.|%5.3fsec\n"};
224 #define START_TIMINGS start=clock(); 225 #define DISPLAY_TIMINGS(ID) \ 227 cout << resultDisplay % STRINGIFY (ID) % (double(stop-start)/CLOCKS_PER_SEC) ; 230 for (I ii =testdata.begin(); ii!=testdata.end(); )
236 CHECK (floor(
double(num)/den) ==
floordiv(num,den));
238 DISPLAY_TIMINGS (Verification)
241 for (I ii =testdata.begin(); ii!=testdata.end(); )
245 DISPLAY_TIMINGS (Integer_div)
248 for (I ii =testdata.begin(); ii!=testdata.end(); )
250 floor (
double(*ii++) / *ii++);
252 DISPLAY_TIMINGS (double_floor)
255 for (I ii =testdata.begin(); ii!=testdata.end(); )
259 DISPLAY_TIMINGS (floordiv_int)
262 for (I ii =testdata.begin(); ii!=testdata.end(); )
264 floordiv (
long(*ii++),
long(*ii++));
266 DISPLAY_TIMINGS (floordiv_long)
269 for (I ii =testdata.begin(); ii!=testdata.end(); )
271 floordiv (int64_t(*ii++), int64_t(*ii++));
273 DISPLAY_TIMINGS (floordiv_int64_t)
276 for (I ii =testdata.begin(); ii!=testdata.end(); )
280 DISPLAY_TIMINGS (floordiv_long_alt)
I floordiv(I num, I den)
floor function for integer arithmetics.
Common functions for handling of time values.
A front-end for using printf-style formatting.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
long integerDiv(long num, long den)
the built-in integer division operator, packaged as inline function for timing comparison ...
Utilities for quantisation (grid alignment) and comparisons.
void runPerformanceTest()
long floordiv_alternate(long num, long den)
an alternate formulation, which turned out to perform slightly worse