source: sasview/src/sas/simulation/iqPy/libiqPy/tnt/tnt_stopwatch.h @ 79492222

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 79492222 was 79492222, checked in by krzywon, 9 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2*
3* Mathematical and Computational Sciences Division
4* National Institute of Technology,
5* Gaithersburg, MD USA
6*
7*
8* This software was developed at the National Institute of Standards and
9* Technology (NIST) by employees of the Federal Government in the course
10* of their official duties. Pursuant to title 17 Section 105 of the
11* United States Code, this software is not subject to copyright protection
12* and is in the public domain.  NIST assumes no responsibility whatsoever for
13* its use by other parties, and makes no guarantees, expressed or implied,
14* about its quality, reliability, or any other characteristic.
15*
16*/
17
18
19
20#ifndef STOPWATCH_H
21#define STOPWATCH_H
22
23// for clock() and CLOCKS_PER_SEC
24#include <time.h>
25
26
27namespace TNT
28{
29
30inline static double seconds(void)
31{
32    const double secs_per_tick = 1.0 / CLOCKS_PER_SEC;
33    return ( (double) clock() ) * secs_per_tick;
34}
35
36class Stopwatch {
37    private:
38        int running_;
39        double start_time_;
40        double total_;
41
42    public:
43        inline Stopwatch();
44        inline void start();
45        inline double stop();
46                inline double read();
47                inline void resume();
48                inline int running();
49};
50
51inline Stopwatch::Stopwatch() : running_(0), start_time_(0.0), total_(0.0) {}
52
53void Stopwatch::start() 
54{
55        running_ = 1;
56        total_ = 0.0;
57        start_time_ = seconds();
58}
59
60double Stopwatch::stop() 
61{
62        if (running_) 
63        {
64         total_ += (seconds() - start_time_); 
65         running_ = 0;
66    }
67    return total_; 
68}
69
70inline void Stopwatch::resume()
71{
72        if (!running_)
73        {
74                start_time_ = seconds();
75                running_ = 1;
76        }
77}
78               
79
80inline double Stopwatch::read()   
81{
82        if (running_)
83        {
84                stop();
85                resume();
86        }
87        return total_;
88}
89
90
91} /* TNT namespace */
92#endif
93   
94
95           
Note: See TracBrowser for help on using the repository browser.