Unity C# C License Last commit Tag Top lang
UltraTimerWindows is a zero-allocation, native high-resolution timer for Unity, built on top of Windows QueryPerformanceCounter.
Suitable for micro-benchmarks and hot-path measurements. Provides sub-millisecond and microsecond-level timing precision.
The overhead of the timer itself is negligible compared to typical Unity workloads.
- β‘ High-resolution native timing in pure C (WinAPI
QueryPerformanceCounter) - π§Ή Zero GC allocations during measurement
- π Deterministic and low-overhead
- π₯ Suitable for micro-benchmarks and hot-path measurements
- βοΈ IL2CPP & Mono compatible
- π§© Scoped measurement via
using - ποΈ Profile sampling for each scope
- π¬ Independent from Unity Profiler
Via UPM: https://github.com/HardCodeDev777/UltraTimerWindows.git?path=Unity
UltraTimerWindows provides very elegant and simple API:
using UnityEngine; // Namespace using HardCodeDev.UltraTimerWindows.Runtime; public class TestTimer : MonoBehaviour { // Timer private UltraTimerWindows _timer; private void Start() => _timer = new(); private void Update() { using (_timer.Measure()) { // Here you can call any methods you want to measure HeavyMethod(); } // See results in the console Debug.Log($"Last elapsed: {_timer.State.lastElapsedMs} ms, " + $"total elapsed: {_timer.State.totalElapsedMs} ms, " + $"average: {_timer.State.averageMs} ms, " + $"called: {_timer.State.countOfCalling} times"); } private void HeavyMethod() { for (int i = 0; i < 100000; i++) { float x = Mathf.Sqrt(i); } } // Don't forget about disposing! private void OnDestroy() => _timer?.Dispose(); }
using (_timer.Measure("Name of Sample")) { // Here you can call any methods you want to measure HeavyMethod(); }
And then after running with enabled Profile you'll see:
using (_timer.Measure()) { // Here you can call any methods you want to measure HeavyMethod(); } if (_timer.State.countOfCalling == 1000) _timer.Reset();
Result:
This project is licensed under the MIT License. See the LICENSE.md file for full terms.