Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85679293
timer.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Oct 1, 03:23
Size
1 KB
Mime Type
text/x-c
Expires
Thu, Oct 3, 03:23 (2 d)
Engine
blob
Format
Raw Data
Handle
21228069
Attached To
rLAMMPS lammps
timer.cpp
View Options
#include "timer.h"
/* -----------------------------------------------------------------------------
* Initialization of time
* -------------------------------------------------------------------------- */
Timer
::
Timer
()
{
flag
=
0
;
start
();
return
;
}
/* -----------------------------------------------------------------------------
* public function, start the timer
* -------------------------------------------------------------------------- */
void
Timer
::
start
()
{
t1
=
clock
();
flag
|=
1
;
return
;
}
/* -----------------------------------------------------------------------------
* public function, stop the timer
* -------------------------------------------------------------------------- */
void
Timer
::
stop
()
{
if
(
flag
&
1
)
{
t2
=
clock
();
flag
|=
2
;
}
return
;
}
/* -----------------------------------------------------------------------------
* public function, print the total time used after timer stops
* -------------------------------------------------------------------------- */
void
Timer
::
print
()
{
if
(
(
flag
&
3
)
!=
3
)
return
;
cpu_time_used
=
((
double
)
(
t2
-
t1
))
/
CLOCKS_PER_SEC
;
printf
(
"Total CPU time used: %g seconds.
\n
"
,
cpu_time_used
);
return
;
}
/* -----------------------------------------------------------------------------
* public function, return the total time used up to now, in seconds
* -------------------------------------------------------------------------- */
double
Timer
::
elapse
()
{
if
(
(
flag
&
3
)
!=
3
)
return
0.
;
else
return
((
double
)
(
t2
-
t1
))
/
CLOCKS_PER_SEC
;
}
Event Timeline
Log In to Comment