nngn
Loading...
Searching...
No Matches
timing.h
Go to the documentation of this file.
1
11#ifndef NNGN_TIMING_TIMING_H
12#define NNGN_TIMING_TIMING_H
13
14#include <chrono>
15
16#include "utils/def.h"
17
18namespace nngn {
19
20struct Timing {
21 using clock = std::chrono::steady_clock;
22 using time_point = clock::time_point;
23 using duration = clock::duration;
24 time_point now = clock::now();
27 float scale = 1.0f;
28 template<typename F> static duration time(F &&f);
29 duration::rep now_ns(void) const;
30 duration::rep now_us(void) const;
31 duration::rep now_ms(void) const;
32 duration::rep now_s(void) const;
33 float fnow_ns(void) const;
34 float fnow_us(void) const;
35 float fnow_ms(void) const;
36 float fnow_s(void) const;
37 duration::rep dt_ns(void) const;
38 duration::rep dt_us(void) const;
39 duration::rep dt_ms(void) const;
40 duration::rep dt_s(void) const;
41 float fdt_ns(void) const;
42 float fdt_us(void) const;
43 float fdt_ms(void) const;
44 float fdt_s(void) const;
45 void update(void);
46};
47
48template<typename F> Timing::duration Timing::time(F &&f) {
49 const auto t0 = Timing::clock::now();
50 f();
51 return Timing::clock::now() - t0;
52}
53
54}
55
56#endif
Definition audio.cpp:7
std::uint64_t u64
Definition def.h:15
local function f()) end
Definition timing.h:20
clock::time_point time_point
Definition timing.h:22
std::chrono::steady_clock clock
Definition timing.h:21
duration::rep now_us(void) const
Definition timing.cpp:19
float fnow_ns(void) const
Definition timing.cpp:27
float fnow_s(void) const
Definition timing.cpp:30
time_point now
Definition timing.h:24
duration::rep dt_ms(void) const
Definition timing.cpp:39
duration::rep now_ms(void) const
Definition timing.cpp:20
float fdt_ns(void) const
Definition timing.cpp:47
duration::rep dt_s(void) const
Definition timing.cpp:40
u64 frame
Definition timing.h:25
static duration time(F &&f)
Definition timing.h:48
float scale
Definition timing.h:27
float fdt_ms(void) const
Definition timing.cpp:49
float fdt_s(void) const
Definition timing.cpp:50
duration::rep dt_us(void) const
Definition timing.cpp:38
float fnow_ms(void) const
Definition timing.cpp:29
duration::rep now_s(void) const
Definition timing.cpp:21
clock::duration duration
Definition timing.h:23
duration::rep dt_ns(void) const
Definition timing.cpp:37
duration dt
Definition timing.h:26
float fdt_us(void) const
Definition timing.cpp:48
void update(void)
Definition timing.cpp:52
float fnow_us(void) const
Definition timing.cpp:28
duration::rep now_ns(void) const
Definition timing.cpp:18