Timer.cpp 1.36 KB
Newer Older
frey_m's avatar
frey_m committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//
// Class Timer
//   This class is used in IpplTimings.
//   https://www.boost.org/doc/libs/1_70_0/libs/timer/doc/cpu_timers.html
//
// Copyright (c) 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// Implemented as part of the PhD thesis
// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
22
#include "Timer.h"
gsell's avatar
gsell committed
23

24 25
Timer::Timer() {
    this->clear();
gsell's avatar
gsell committed
26 27 28
}


29 30
void Timer::clear() {
    wall_m = user_m = sys_m = 0.0;
gsell's avatar
gsell committed
31 32 33
}


34 35
void Timer::start() {
    timer_m.start();
gsell's avatar
gsell committed
36
}
37

gsell's avatar
gsell committed
38

39 40 41 42 43 44 45 46
void Timer::stop() {
    timer_m.stop();
    
    boost::timer::cpu_times elapsed = timer_m.elapsed();
    
    wall_m += elapsed.wall;
    user_m += elapsed.user;
    sys_m  += elapsed.system;
gsell's avatar
gsell committed
47 48 49
}


50 51
double Timer::clock_time() {
    return wall_m * 1.0e-9;
gsell's avatar
gsell committed
52 53 54
}


55 56
double Timer::user_time() {
    return user_m * 1.0e-9;
gsell's avatar
gsell committed
57 58 59
}


60 61
double Timer::system_time() {
    return sys_m * 1.0e-9;
gsell's avatar
gsell committed
62 63 64
}


65 66
double Timer::cpu_time() {
    return (user_m + sys_m) * 1.0e-9;
gsell's avatar
gsell committed
67
}