summaryrefslogtreecommitdiff
path: root/audio/tests/KSPosTst/timetest.cpp
blob: d8026716ea3b8079ceeb56c19f1b15ea3ec5fe64 (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
43
44
45
46
47
48
49
50
// ------------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// Module Name:
//
//  timetest.cpp
//
// Abstract:
//
//  Functions to precisely measure time.
//
// -------------------------------------------------------------------------------

#include "PreComp.h"
#include <math.h>

// ------------------------------------------------------------------------------
// returns millisecs
double tpQPC (void)
{
    static LARGE_INTEGER liFrequency = { 0 };
    static LARGE_INTEGER liStart = { 0 };
    static bool bInitialized = false;

    if (!bInitialized)
    {
        if (!QueryPerformanceFrequency(&liFrequency))
        {
            throw ("QueryPerformanceFrequency failed");
        }
        
        if (!QueryPerformanceCounter(&liStart))
        {
            throw ("QueryPerformanceCounter failed");
        }
        
        bInitialized = true;
    }

    LARGE_INTEGER liNow = { 0 };

    if (!QueryPerformanceCounter(&liNow))
    {
        throw ("QueryPerformanceCounter failed");
    }

    // milliseconds since test start
    return 1000.0 * (liNow.QuadPart - liStart.QuadPart) / liFrequency.QuadPart;
}