summaryrefslogtreecommitdiffstats
path: root/Whisper/Utils/CpuProfiler.h
blob: 17887f81bebf3fd0b50e1176ab878f15b7d1977c (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
#pragma once

namespace Whisper
{
	// Get current time in CPU clock
	// More specifically, each CPU core has a timestamp counter which runs at CPU's base frequency, regardless on the frequency scaling of that core.
	inline int64_t tscNow()
	{
		return __rdtsc();
	}

	// Scale the time interval from CPU time stamp counter clock into 100-nanosecond ticks, rounding to nearest
	uint64_t ticksFromTsc( uint64_t tscDiff );

	class CpuProfiler
	{
		const int64_t started = tscNow();

	public:

		uint64_t elapsed() const
		{
			return ticksFromTsc( (uint64_t)( tscNow() - started ) );
		}
	};
}