GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - HardCodeDev777/UltraTimerWindows: Zero-allocation, native high-resolution timer for Unity. Suitable for micro-benchmarks and hot-path measurements

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
Native
Native
 
 
Unity
Unity
 
 
media
media
 
 
.gitattributes
.gitattributes
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 

Repository files navigation

Unity C# C License Last commit Tag Top 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

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();  
}

๐ŸŽž๏ธ Profile Sampling

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:


๐Ÿซก Reset Timer

using (_timer.Measure()) 
{
  // Here you can call any methods you want to measure
  HeavyMethod();
}

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

ccsharpmeasurementsqueryperformancecounterunityunity-engineunity-toolwinapizero-allocation

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Contributors

Languages

You are visitor 01402520 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.