Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Timer.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file basic/gpu/Timer.cc
11 /// @brief High-resolution Timer (ns resolution)
12 /// @author Luki Goldschmidt (luki@mbi.ucla.edu)
13 
14 #ifndef INCLUDED_basic_gpu_GPU_cc
15 #define INCLUDED_basic_gpu_GPU_cc
16 
17 #include <basic/gpu/Timer.hh>
18 #include <iostream>
19 
20 namespace basic {
21 namespace gpu {
22 
24  tag_ = NULL;
25  t_ = NULL;
26  Reset();
27 }
28 
30  Report(tag_);
31 }
32 
33 Timer::Timer(const char *tag) {
34  t_ = NULL;
35  tag_ = tag;
36  Reset();
37 }
38 
40  t_ = &t;
41  tag_ = tag;
42  Reset();
43 }
44 
45 #ifdef WIN32
46 void Timer::Reset() {
47  start = clock();
48 }
49 
50 double Timer::GetTime() {
51  end = clock();
52  double time = 1000 * (end-start) / CLOCKS_PER_SEC;
53  return time;
54 }
55 
56 #else
57 
58 void Timer::Reset() {
59  gettimeofday(&start, NULL);
60 }
61 
62 double Timer::GetTime() {
63  gettimeofday(&end, NULL);
64  double time = ((end.tv_sec - start.tv_sec)*1000 + (end.tv_usec - start.tv_usec)/1000.);
65  return time;
66 }
67 #endif
68 
69 void Timer::Report(const char *tag) {
70 
71  double time = GetTime();
72  if ( t_ ) {
73  if ( tag ) {
74  (*t_) << "Time [" << tag << "]: ";
75  } else {
76  (*t_) << "Time: ";
77  }
78  (*t_) << time << " ms" << std::endl;
79  } else {
80  if ( tag_ ) {
81  std::cout << "Time [" << tag << "]: ";
82  } else {
83  std::cout << "Time: ";
84  }
85  std::cout << time << " ms" << std::endl;
86  }
87 }
88 
89 } // gpu
90 } // basic
91 
92 #endif // INCLUDED_basic_gpu_GPU_cc
void Report(const char *tag=NULL)
Definition: Timer.cc:69
double GetTime()
Definition: Timer.cc:62
High-resolution Timer (ns resolution, but on *nix only)
struct timeval start end
Definition: Timer.hh:32
void Reset()
Definition: Timer.cc:58
const char * tag_
Definition: Timer.hh:34
Small inner class acting as a proxy to an object that hold it.
Definition: Tracer.hh:228
basic::Tracer::TracerProxy * t_
Definition: Timer.hh:35
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
rule< Scanner, tag_closure::context_t > tag
Definition: Tag.cc:373