42 const uint NUM_ELMS_PERFORMANCE_TEST = 50000000;
43 const uint NUMBER_LIMIT = 1 << 30;
45 typedef std::vector<int> VecI;
48 buildTestNumberz (uint cnt)
51 for (uint i=0; i<cnt; ++i)
53 int someNumber = -int(NUMBER_LIMIT)+
rani(2*NUMBER_LIMIT);
54 if (!someNumber) someNumber -= 1 +
rani(NUMBER_LIMIT);
56 data.push_back (someNumber);
78 ldiv_t res = ldiv(num,den);
79 return (0 >= res.quot && res.rem)? res.quot-1
113 verifyIntegerTypes<int>();
114 verifyIntegerTypes<long>();
115 verifyIntegerTypes<short>();
116 verifyIntegerTypes<int64_t>();
117 verifyIntegerTypes<llong>();
157 verifyIntegerTypes ()
161 for (
int i=-12; i <= 12; ++i)
166 CHECK (
floordiv(n,d) == expectedRes);
210 VecI testdata = buildTestNumberz (2*NUM_ELMS_PERFORMANCE_TEST);
211 typedef VecI::const_iterator I;
213 clock_t start(0), stop(0);
214 _Fmt resultDisplay{
"timings(%s)%|30T.|%5.3fsec\n"};
216 #define START_TIMINGS start=clock(); 217 #define DISPLAY_TIMINGS(ID) \ 219 cout << resultDisplay % STRINGIFY (ID) % (double(stop-start)/CLOCKS_PER_SEC) ; 222 for (I ii =testdata.begin(); ii!=testdata.end(); )
228 CHECK (floor(
double(num)/den) ==
floordiv(num,den));
230 DISPLAY_TIMINGS (Verification)
233 for (I ii =testdata.begin(); ii!=testdata.end(); )
237 DISPLAY_TIMINGS (Integer_div)
240 for (I ii =testdata.begin(); ii!=testdata.end(); )
242 floor (
double(*ii++) / *ii++);
244 DISPLAY_TIMINGS (double_floor)
247 for (I ii =testdata.begin(); ii!=testdata.end(); )
251 DISPLAY_TIMINGS (floordiv_int)
254 for (I ii =testdata.begin(); ii!=testdata.end(); )
256 floordiv (
long(*ii++),
long(*ii++));
258 DISPLAY_TIMINGS (floordiv_long)
261 for (I ii =testdata.begin(); ii!=testdata.end(); )
263 floordiv (int64_t(*ii++), int64_t(*ii++));
265 DISPLAY_TIMINGS (floordiv_int64_t)
268 for (I ii =testdata.begin(); ii!=testdata.end(); )
272 DISPLAY_TIMINGS (floordiv_long_alt)
I floordiv(I num, I den)
floor function for integer arithmetics.
Common functions for handling of time values.
int rani(uint bound=_iBOUND())
A front-end for using printf-style formatting.
Simplistic 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