Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

UnityC#CLicenseLast commitTagTop lang

🔥 UltraTimerWindows


🚀 Overview

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.


✨ Features

  • 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

📦 Installation

Via UPM: https://github.com/HardCodeDev777/UltraTimerWindows.git?path=Unity


💻 Usage

UltraTimerWindows provides very elegant and simple API:


💡 Basic example of usage

usingUnityEngine;// NamespaceusingHardCodeDev.UltraTimerWindows.Runtime;publicclassTestTimer:MonoBehaviour{// TimerprivateUltraTimerWindows_timer;privatevoidStart()=>_timer=new();privatevoidUpdate(){using(_timer.Measure()){// Here you can call any methods you want to measureHeavyMethod();}// See results in the consoleDebug.Log($"Last elapsed: {_timer.State.lastElapsedMs} ms, "+$"total elapsed: {_timer.State.totalElapsedMs} ms, "+$"average: {_timer.State.averageMs} ms, "+$"called: {_timer.State.countOfCalling} times");}privatevoidHeavyMethod(){for(inti=0;i<100000;i++){floatx=Mathf.Sqrt(i);}}// Don't forget about disposing!privatevoidOnDestroy()=>_timer?.Dispose();}

🎞️ Profile Sampling

using(_timer.Measure("Name of Sample")){// Here you can call any methods you want to measureHeavyMethod();}

And then after running with enabled Profile you'll see:


🫡 Reset Timer

using(_timer.Measure()){// Here you can call any methods you want to measureHeavyMethod();}if(_timer.State.countOfCalling==1000)_timer.Reset();

Result:


That's it! Enjoy measuring your heavy stuff 😎


📄 License

This project is licensed under the MIT License. See the LICENSE.md file for full terms.

About

Zero-allocation, native high-resolution timer for Unity. Suitable for micro-benchmarks and hot-path measurements

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Contributors

Languages