Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
6c6390d9
Commit
6c6390d9
authored
18 years ago
by
Markus Blatt
Browse files
Options
Downloads
Patches
Plain Diff
Added define to switch from rusage to std::clock
Use C++ headers instead of C headers [[Imported from SVN: r4783]]
parent
ae618da4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/timer.hh
+17
-3
17 additions, 3 deletions
common/timer.hh
with
17 additions
and
3 deletions
common/timer.hh
+
17
−
3
View file @
6c6390d9
...
...
@@ -3,13 +3,15 @@
#ifndef DUNE_TIMER_HH
#define DUNE_TIMER_HH
#ifndef TIMER_USE_STD_CLOCK
// headers for getrusage(2)
#include
<sys/time.h>
#include
<sys/resource.h>
#include
<unistd.h>
#endif
#include
<ctime>
// headers for stderror(3)
#include
<string
.h
>
#include
<
c
string>
// access to errno in C++
#include
<cerrno>
...
...
@@ -52,23 +54,35 @@ namespace Dune {
//! Reset timer
void
reset
()
throw
(
TimerError
)
{
#ifdef TIMER_USE_STD_CLOCK
cstart
=
std
::
clock
();
#else
rusage
ru
;
if
(
getrusage
(
RUSAGE_SELF
,
&
ru
))
DUNE_THROW
(
TimerError
,
strerror
(
errno
));
cstart
=
ru
.
ru_utime
;
#endif
}
//! Get elapsed user-time in seconds
double
elapsed
()
const
throw
(
TimerError
)
{
#ifdef TIMER_USE_STD_CLOCK
return
(
std
::
clock
()
-
cstart
)
/
static_cast
<
double
>
(
CLOCKS_PER_SEC
);
#else
rusage
ru
;
if
(
getrusage
(
RUSAGE_SELF
,
&
ru
))
DUNE_THROW
(
TimerError
,
strerror
(
errno
));
return
1.0
*
(
ru
.
ru_utime
.
tv_sec
-
cstart
.
tv_sec
)
+
(
ru
.
ru_utime
.
tv_usec
-
cstart
.
tv_usec
)
/
(
1000.0
*
1000.0
);
#endif
}
private
:
#ifdef TIMER_USE_STD_CLOCK
std
::
clock_t
cstart
#else
struct
timeval
cstart
;
#endif
};
// end class Timer
/** @} end documentation */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment