source: trunk/IPs/systemC/processor/Morpheo/Common/include/Time.h @ 88

Last change on this file since 88 was 88, checked in by rosiere, 15 years ago

Almost complete design
with Test and test platform

  • Property svn:keywords set to Id
File size: 1.2 KB
Line 
1#ifndef Morpheo_Time_h
2#define Morpheo_Time_h
3
4#ifdef SYSTEMC
5#include "systemc.h"
6#endif
7
8#include <string>
9#include <iostream>
10#include <sys/time.h>
11
12namespace morpheo {
13
14class Time
15{
16#ifdef SYSTEMC
17private : double   nb_cycles_begin;
18#endif
19private : timeval  time_begin;
20// private : timeval time_end;
21 
22public  : Time ()
23  { 
24#ifdef SYSTEMC
25    nb_cycles_begin = sc_simulation_time();
26#endif
27    gettimeofday(&time_begin,NULL);
28  };
29 
30public  : ~Time ()
31  {
32    std::cout << *this;
33  };
34
35public  : friend std::ostream& operator<< (std::ostream& output,
36                                           const Time & x)
37  {
38    timeval time_end;
39   
40    gettimeofday(&time_end,NULL);
41   
42#ifdef SYSTEMC
43    double nb_cycles_end = sc_simulation_time();
44    double average       = static_cast<double>(nb_cycles_end-x.nb_cycles_begin+1) / static_cast<double>(time_end.tv_sec-x.time_begin.tv_sec+1);
45   
46    output << "Timing : " << nb_cycles_end << " cycles \t(" << average << " cycles/s)" << std::endl;
47#else
48    double average       = static_cast<double>(time_end.tv_sec-x.time_begin.tv_sec+1);
49   
50    output << "Timing : " average << " s" << std::endl;
51#endif
52   
53    return output;
54  }
55};
56
57}; // end namespace morpheo
58
59#endif
Note: See TracBrowser for help on using the repository browser.