Include file for Realtime Integer Library of Equations Timers
Optimizing code for speed requires accurate measurement of execution time.
This section gives code for timing operations for the following
For the StrongARM 32-bit integer processor used in many low-power applications, we use is MIT’s web-based tool
For more details, (mirror) http://www.cl.cam.ac.uk/Teaching/1998/CompDesn/fromlecturer/htmlman/armcc.html
In order to use JouleTrack, everything must be bundled into a single monolithic source file.
Specifically, it does not seem to support include files and data files.
For Pentium CPUs, we use the RDTSC CPU counter.
On UNIX systems, compile with the flag I586 defined
gcc –DI586 ….
#include <time.h>
#ifdef __WIN32
// CPUID force previous instuctions to finish
// RDTSC opcode, result Int64 in EAX and EDX
volatile unsigned __int64 RDTSC()
{ __asm __emit 0fh __asm __emit 0a2h
__asm __emit 0fh __asm __emit 031h }
volatile unsigned __int64 prog_start, prog_end;
#else // _WIN32
// CPUID force previous instuctions to finish
// RDTSC opcode, result Int64 in EAX and EDX
volatile unsigned long long RDTSC()
{// __asm__ volatile(".byte 0x0f,0xa2"); // Causes segmentation faults on some systems
__asm__ volatile(".byte 0x0f,0x31"); }
volatile unsigned long long prog_start, prog_end;
int NCyc;
#endif // _WIN32
int main()
{ int i,j,k;
prog_start = RDTSC();
prog_start = RDTSC();
prog_start = RDTSC();
// Code to be timed
{
:
}
prog_end = RDTSC();
NCyc = (int)((prog_end>prog_start) ? prog_end-prog_start :
prog_end + (0xFFFFFFFFFFFFFFFFu - prog_start));
printf("%6.0f ~%7.0E operations took %9u cycles, %4.2f cycles/OPT\n",
NOPT, NOPT, NCyc, NCyc / NOPT);
For UNIX systems we generally use gettimeofday()
#include <time.h>
#include <sys/time.h>
int main ()
{ int i,j,k;
int dt_us;
struct timeval tv_start, tv_end;
gettimeofday(&tv_start, NULL);
{
:
}
// Accurate CPU speed info found in linux at /proc/cpuinfo
gettimeofday(&tv_end, NULL);
dt_us = tv_end.tv_usec - tv_start.tv_usec + 1000000 *
((tv_end.tv_sec >= tv_start.tv_sec) ? tv_end.tv_sec - tv_start.tv_sec :
tv_end.tv_sec - tv_start.tv_sec + 60);
printf("%6.0f ~%7.0E operations took %9d u-sec, %9.1f ns/OPT\n",
NOPT, NOPT, dt_uv, dt_uv * 1e3 / NOPT);
Questions, comments, better code?
Please e-mail me at