File: timer.h

package info (click to toggle)
libloki 0.1.5-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,888 kB
  • ctags: 5,535
  • sloc: cpp: 22,174; ansic: 1,955; makefile: 359; php: 316; perl: 108
file content (87 lines) | stat: -rwxr-xr-x 2,219 bytes parent folder | download
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
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2005 Peter Kmmel
// Permission to use, copy, modify, distribute and sell this software for any 
//     purpose is hereby granted without fee, provided that the above copyright 
//     notice appear in all copies and that both that copyright notice and this 
//     permission notice appear in supporting documentation.
// The authors make no representations about the 
//     suitability of this software for any purpose. It is provided "as is" 
//     without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////

// $Header: /cvsroot/loki-lib/loki/test/SmallObj/timer.h,v 1.6 2006/01/19 23:11:57 lfittl Exp $

#ifndef LOKI_TEST_TIMER_H
#define LOKI_TEST_TIMER_H


#include <ctime>
#include <iostream>
#include <stdlib.h>
#include <cmath>

class Timer 
{
public:

    Timer()
    {
        t100 = 0;
    };

    void start()
    {
        t0 = clock();
    }

    void stop()
    {
        t1 = clock();
    }
    
    int t()
    {
        return t1-t0;
    }

    double sec(int t)
    { 
        return floor(100.0*double(t)/1000.0 )/100.0; 
    }
    
    int rel(int t)
    {
        return ( t100==0 ? 100 : static_cast<int>(floor(100.0*t/t100+0.5)) ); 
    }
    
    double speedup(int t)
    {
        double tup=t;
        return (tup!=0 ? floor(100.0*(t100!=0?t100:tup)/tup+0.5)/100 : 1);
    }

    double  t100;

    void print(int t, const char* s)
    {
        std::cout << s << "\tseconds: " << sec(t) << "\trelative time: " << rel(t) << "%\tspeed-up factor: " << speedup(t) << "" << std::endl;
    }
private:
    int t0;
    int t1;
};

#endif

// $Log: timer.h,v $
// Revision 1.6  2006/01/19 23:11:57  lfittl
// - Disabled -Weffc++ flag, fixing these warnings produces too much useless code
// - Enabled -pedantic, -Wold-style-cast and -Wundef for src/ and test/
//
// Revision 1.5  2005/10/30 14:03:23  syntheticpp
// replace tabs space
//
// Revision 1.4  2005/10/26 00:38:49  rich_sposato
// Added CVS keywords and header lines.
//