forked from jonpalmisc/ObjectiveNinja
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Performance.h
38 lines (33 loc) · 873 Bytes
/
Performance.h
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
/*
* Copyright (c) 2022-2023 Jon Palmisciano. All rights reserved.
*
* Use of this source code is governed by the BSD 3-Clause license; the full
* terms of the license can be found in the LICENSE.txt file.
*/
#pragma once
#include <chrono>
using high_res_clock = std::chrono::high_resolution_clock;
/**
* Utilities for measuring performance.
*/
class Performance {
public:
/**
* Get the current time.
*/
static high_res_clock::time_point now()
{
return high_res_clock::now();
}
/**
* Get the current elapsed time from a given start time.
*
* Accepts a unit of measure template parameter for the result.
*/
template <typename T>
static T elapsed(high_res_clock::time_point start)
{
auto end = high_res_clock::now();
return std::chrono::duration_cast<T>(end - start);
}
};