summaryrefslogtreecommitdiff
path: root/shared/perf.h
blob: 62473259108df8044b83d394b736cc633beaf737 (plain)
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
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************
//
#include <windows.h>
#include <sstream>

class Performance
{
public:
    Performance() : resultWasShown(false), startTime(::GetTickCount()) {}

    ~Performance()
    {
        if (!resultWasShown)
            showResult();
    }

    void showResult()
    {
        resultWasShown = true;

        const DWORD currentTime = ::GetTickCount();
        const DWORD delta = currentTime - startTime;
        startTime = currentTime;

        std::ostringstream ss;
        ss << delta << " ms";

        ::MessageBoxA(NULL, ss.str().c_str(), "Timer", 0);
    }

private:
    bool resultWasShown;
    DWORD startTime;
};

//two macros for quick performance measurements
#define PERF_START Performance a;
#define PERF_STOP  a.showResult();
bgstack15