Atlas-C++
timer.h
1 #include <time.h>
2 #include <sstream>
3 #include <iostream>
4 
5 clock_t calc_time0,calc_time1;
6 double calc_time;
7 
8 void printTime(const std::string& msg, long long iterations, double iterPerSec) {
9  std::stringstream ss;
10  ss << msg;
11  while (ss.tellp() < 30) {
12  ss << ' ';
13  }
14  ss << " iterations=" << iterations;
15  while (ss.tellp() < 60) {
16  ss << ' ';
17  }
18  ss <<" CPU Time="<<std::fixed<<calc_time;
19  while (ss.tellp() < 80) {
20  ss << ' ';
21  }
22  ss <<" iter/s="<<iterPerSec<<std::endl;
23  std::cout << ss.str() << std::flush;
24 }
25 
26 
27 #define TIME_ON calc_time0=clock();
28 #define TIME_OFF(msg) calc_time1=clock(); \
29  calc_time=(double)(calc_time1-calc_time0)/CLOCKS_PER_SEC; \
30  printTime(msg, i, i/calc_time);
31 

Copyright 2000-2004 the respective authors.

This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.