timer() : A platform-independent timer with microsecond accuracy:
Example: single timer
timer::start();
printf("elapsed seconds: %g\n", timer::stop());
Example: multiple timers
timer start1 = timer::start();
timer start2 = timer::start();
printf("elapsed seconds: %g\n", timer::stop(start1));
printf("elapsed seconds: %g\n", timer::stop(start2));
struct af::timer timer
Internal timer object.
Accurate and reliable measurement of performance involves several factors:
- Executing enough iterations to achieve peak performance.
- Executing enough repetitions to amortize any overhead from system timers.
To take care of much of this boilerplate, timeit provides accurate and reliable estimates of both CPU or GPU code.
Here`s a stripped down example of Monte-Carlo estimation of PI making use of timeit. Notice how it expects a void
function pointer.
#include <stdio.h>
void pi_function() {
int n = 20e6;
float pi = 4.0 * sum<float>(
sqrt(x*x + y*y)) < 1) / n;
}
int main() {
printf(
"pi_function took %g seconds\n",
timeit(pi_function));
return 0;
}
A multi dimensional data container.
Definition: array.h:27
@ f32
32-bit floating point values
Definition: defines.h:196
AFAPI array sqrt(const array &in)
C++ Interface for square root of input.
AFAPI array randu(const dim4 &dims, const dtype ty=f32)
Definition: algorithm.h:15
AFAPI double timeit(void(*fn)())
This produces:
pi_function took 0.007252 seconds
(test machine: Core i7 920 @ 2.67GHz with a Tesla C2070)