1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
/* tests/timer.C
* Copyright (C) 1994-1997 Givaro Team
*
* Written by T. Gautier
* Imported from LinBox by Clément Pernet.
*
* ========LICENCE========
* This file is part of the library FFLAS-FFPACK.
*
* FFLAS-FFPACK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*
* This file implements the C++ interface to commentators (for
* providing runtime commentary to the user)
*/
#ifndef __FFLASFFPACK_timer_C
#define __FFLASFFPACK_timer_C
// Description:
// - various timer objects
// - to be rewritten to be more efficient
#include <cmath>
extern "C" {
# include <sys/time.h>
# include <sys/resource.h>
// int getrusage (int, struct rusage*) ;
}
#include <iostream>
#include "timer.h"
// Return a value to initialize random generator
long BaseTimer::seed()
{
struct timeval tp;
gettimeofday(&tp, 0) ;
return(tp.tv_usec);
}
// Output the value of the timer :
std::ostream& BaseTimer::print( std::ostream& o ) const
{ return o << _t ; }
// Some arithmetic operator :
BaseTimer& BaseTimer::operator = (const BaseTimer & T)
{
_t = T._t ;
return *this ;
}
// Computes and returns interval of time
// beteween *this and T
const BaseTimer BaseTimer::operator - (const BaseTimer & T) const
{
BaseTimer Tmp ;
Tmp._t = _t - T._t ;
return Tmp ;
}
const BaseTimer BaseTimer::operator - ()
{
BaseTimer Tmp ;
Tmp._t = -_t ;
return Tmp ;
}
const BaseTimer BaseTimer::operator + (const BaseTimer & T) const
{
BaseTimer Tmp ;
Tmp._t = _t + T._t ;
return Tmp ;
}
// Start timer
void RealTimer::start()
{
struct timeval tmp2 ;
gettimeofday (&tmp2, 0) ;
// real time
_t = (double) tmp2.tv_sec +
((double) tmp2.tv_usec)/ (double)BaseTimer::MSPSEC ;
}
// Stop timer
void RealTimer::stop()
{
struct timeval tmp2 ;
gettimeofday (&tmp2, 0) ;
// real time
_t = (double) tmp2.tv_sec +
((double) tmp2.tv_usec)/ (double)BaseTimer::MSPSEC - _t ;
}
// Start timer
void UserTimer::start()
{
struct rusage tmp1 ; // to getrusage (sys+user times)
getrusage (RUSAGE_SELF, &tmp1) ;
// user time
_t = (double) tmp1.ru_utime.tv_sec +
((double) tmp1.ru_utime.tv_usec)/ (double)MSPSEC ;
}
// Stop timer
void UserTimer::stop()
{
struct rusage tmp1 ; // to getrusage (sys+user times)
getrusage (RUSAGE_SELF, &tmp1) ;
// user time
_t = (double) tmp1.ru_utime.tv_sec +
((double) tmp1.ru_utime.tv_usec)/ (double)MSPSEC - _t ;
}
// Start timer
void SysTimer::start()
{
struct rusage tmp1 ; // to getrusage (sys+user times)
getrusage (RUSAGE_SELF, &tmp1) ;
// user time
_t = (double) tmp1.ru_stime.tv_sec +
((double) tmp1.ru_stime.tv_usec)/ (double)MSPSEC ;
}
// Stop timer
void SysTimer::stop()
{
struct rusage tmp1 ; // to getrusage (sys+user times)
getrusage (RUSAGE_SELF, &tmp1) ;
// user time
_t = (double) tmp1.ru_stime.tv_sec +
((double) tmp1.ru_stime.tv_usec)/ (double)MSPSEC - _t ;
}
// Clear timer :
void Timer::clear()
{ rt.clear() ; ut.clear(); st.clear() ; }
// Start timer
void Timer::start()
{ rt.start() ; ut.start(); st.start() ; }
// Stop timer
void Timer::stop()
{ rt.stop() ; ut.stop(); st.stop() ; }
std::ostream& Timer::print( std::ostream& o ) const
{
o << "user time: " << usertime() << '\n' ;
o << "sys. time: " << systime() << '\n' ;
return o << "real time: " << realtime() << std::endl ;
}
// Some arithmetic operator :
Timer& Timer::operator = (const Timer & T)
{
ut = T.ut ;
st = T.st ;
rt = T.rt ;
return *this ;
}
// Comput._tes and returns interval of time
// beteween *this and T
const Timer Timer::operator - (const Timer & T) const
{
Timer Tmp ;
Tmp.ut = ut - T.ut ;
Tmp.st = st - T.st ;
Tmp.rt = rt - T.rt ;
return Tmp ;
}
const Timer Timer::operator - ()
{
Timer Tmp ;
Tmp.ut = -ut ;
Tmp.st = -st ;
Tmp.rt = -rt ;
return Tmp ;
}
const Timer Timer::operator + (const Timer & T) const
{
Timer Tmp ;
Tmp.ut = ut + T.ut ;
Tmp.st = st + T.st ;
Tmp.rt = rt + T.rt ;
return Tmp ;
}
#endif
|