comparison armadillo-2.4.4/include/armadillo_bits/wall_clock_meat.hpp @ 0:8b6102e2a9b0

Armadillo Library
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 09:27:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8b6102e2a9b0
1 // Copyright (C) 2008-2012 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2012 Conrad Sanderson
3 //
4 // This file is part of the Armadillo C++ library.
5 // It is provided without any warranty of fitness
6 // for any purpose. You can redistribute this file
7 // and/or modify it under the terms of the GNU
8 // Lesser General Public License (LGPL) as published
9 // by the Free Software Foundation, either version 3
10 // of the License or (at your option) any later version.
11 // (see http://www.opensource.org/licenses for more info)
12
13
14 //! \addtogroup wall_clock
15 //! @{
16
17
18 inline
19 wall_clock::wall_clock()
20 : valid(false)
21 {
22 arma_extra_debug_sigprint();
23 }
24
25
26
27 inline
28 wall_clock::~wall_clock()
29 {
30 arma_extra_debug_sigprint();
31 }
32
33
34
35 inline
36 void
37 wall_clock::tic()
38 {
39 arma_extra_debug_sigprint();
40
41 #if defined(ARMA_USE_BOOST_DATE)
42 {
43 boost_time1 = boost::posix_time::microsec_clock::local_time();
44 valid = true;
45 }
46 #elif defined(ARMA_HAVE_GETTIMEOFDAY)
47 {
48 gettimeofday(&posix_time1, 0);
49 valid = true;
50 }
51 #else
52 {
53 time1 = clock();
54 valid = true;
55 }
56 #endif
57 }
58
59
60
61 inline
62 double
63 wall_clock::toc()
64 {
65 arma_extra_debug_sigprint();
66
67 if(valid)
68 {
69 #if defined(ARMA_USE_BOOST_DATE)
70 {
71 boost_duration = boost::posix_time::microsec_clock::local_time() - boost_time1;
72 return boost_duration.total_microseconds() * 1e-6;
73 }
74 #elif defined(ARMA_HAVE_GETTIMEOFDAY)
75 {
76 gettimeofday(&posix_time2, 0);
77
78 const double tmp_time1 = posix_time1.tv_sec + posix_time1.tv_usec * 1.0e-6;
79 const double tmp_time2 = posix_time2.tv_sec + posix_time2.tv_usec * 1.0e-6;
80
81 return tmp_time2 - tmp_time1;
82 }
83 #else
84 {
85 clock_t time2 = clock();
86
87 clock_t diff = time2 - time1;
88
89 return double(diff) / double(CLOCKS_PER_SEC);
90 }
91 #endif
92 }
93 else
94 {
95 return 0.0;
96 }
97 }
98
99
100
101 //! @}
102