Skip to content

Instantly share code, notes, and snippets.

@ddutchie
Created March 29, 2019 15:07
Show Gist options
  • Save ddutchie/2d998d7c64808dd73cd6117615235680 to your computer and use it in GitHub Desktop.
Save ddutchie/2d998d7c64808dd73cd6117615235680 to your computer and use it in GitHub Desktop.
Speed Of Ray Trace
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class RayTraceSpeed : MonoBehaviour
{
public TMPro.TextMeshProUGUI m_UIPerfText;
Stopwatch m_Stopwatch = new Stopwatch();
int m_UpdateCounter;
int m_FrameCounter;
long m_RayCounter;
// Start is called before the first frame update
public void StartLoop()
{
m_Stopwatch.Start();
//RayCount
}
public void EndLoop(int rayCount)
{
++m_UpdateCounter;
++m_FrameCounter;
m_RayCounter += rayCount;
}
// Update is called once per frame
public void Update()
{
if (m_UpdateCounter == 10)
{
m_Stopwatch.Stop();
var s = (float)((double)m_Stopwatch.ElapsedTicks / (double)Stopwatch.Frequency) / m_UpdateCounter;
int FPS = (int)(1f / Time.unscaledDeltaTime);
var ms = s * 1000.0f;
var mrayS = m_RayCounter / m_UpdateCounter / s * 1.0e-6f;
var mrayFr = m_RayCounter / m_UpdateCounter * 1.0e-6f;
m_UIPerfText.text = string.Format("{0:F2}ms ({1:F2}FPS) {2:F2}Mrays/s {3:F2}Mrays/frame {4} frames", ms, 1 / s, mrayS, mrayFr, m_FrameCounter);
m_UpdateCounter = 0;
m_RayCounter = 0;
m_Stopwatch.Reset();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment