Last active
August 29, 2015 14:22
-
-
Save webcoyote/a0e11799a91a2d967083 to your computer and use it in GitHub Desktop.
Revisions
-
webcoyote revised this gist
Jun 11, 2015 . 1 changed file with 22 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,27 +29,26 @@ public float Delta () { private float LastValue; }; private TimeFunc[] m_times; void Awake () { m_times = new TimeFunc[] { // Time functions new TimeFunc("tick", () => Environment.TickCount / 1000f), new TimeFunc("stop", () => Stopwatch.GetTimestamp() / 1000f / 10000f), new TimeFunc("real", () => Time.realtimeSinceStartup), new TimeFunc("time", () => Time.time), new TimeFunc("levl", () => Time.timeSinceLevelLoad), new TimeFunc("fixd", () => Time.fixedTime), new TimeFunc("unsc", () => Time.unscaledTime), // Value functions new TimeFunc("*scale", () => Time.timeScale, false), new TimeFunc("*delta", () => Time.deltaTime * 1000f, false), new TimeFunc("*smoot", () => Time.smoothDeltaTime * 1000f, false), new TimeFunc("*unsca", () => Time.unscaledDeltaTime * 1000f, false), }; Application.targetFrameRate = TargetFrameRate; m_frameCount = 0; } @@ -60,9 +59,13 @@ void Update () { m_frameCount = 0; var sb = new StringBuilder(256); sb.Append(DateTime.UtcNow.ToLongTimeString()); foreach (var time in m_times) sb.AppendFormat(" {0}:{1:0.0}", time.Name, time.Delta()); UnityEngine.Debug.Log(sb.ToString()); } const int TargetFrameRate = 60; int m_frameCount; } -
webcoyote revised this gist
Jun 11, 2015 . 1 changed file with 53 additions and 25 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,38 +3,66 @@ using System.Threading; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; public class Main : MonoBehaviour { private class TimeFunc { public TimeFunc (string name, Func<float> time, bool applyDelta = true) { Name = name; Time = time; ApplyDelta = applyDelta; LastValue = time(); } public float Delta () { var curr = Time(); if (!ApplyDelta) return curr; var delta = curr - LastValue; LastValue = curr; return delta; } public readonly string Name; private readonly Func<float> Time; private readonly bool ApplyDelta; private float LastValue; }; private readonly TimeFunc[] m_times = new TimeFunc[] { // Time functions new TimeFunc("tick", () => Environment.TickCount / 1000f), new TimeFunc("stop", () => Stopwatch.GetTimestamp() / 1000f / 10000f), new TimeFunc("real", () => Time.realtimeSinceStartup), new TimeFunc("time", () => Time.time), new TimeFunc("levl", () => Time.timeSinceLevelLoad), new TimeFunc("fixd", () => Time.fixedTime), new TimeFunc("unsc", () => Time.unscaledTime), // Value functions new TimeFunc("*delta", () => Time.deltaTime, false), new TimeFunc("*smoot", () => Time.smoothDeltaTime, false), new TimeFunc("*scale", () => Time.timeScale, false), new TimeFunc("*unsca", () => Time.unscaledDeltaTime, false), }; const int TargetFrameRate = 10; int m_frameCount; void Start () { Application.targetFrameRate = TargetFrameRate; m_frameCount = 0; } void Update () { if (++m_frameCount < TargetFrameRate) return; m_frameCount = 0; var sb = new StringBuilder(256); sb.Append(DateTime.UtcNow.ToShortTimeString()); foreach (var time in m_times) sb.AppendFormat(" {0}:{1:0.0}", time.Name, time.Delta()); UnityEngine.Debug.Log(sb.ToString()); } } -
webcoyote revised this gist
Jun 10, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,27 +7,27 @@ public class Main : MonoBehaviour { int lastTicks; long lastStop; float lastRun; float lastReal; void Start () { lastTicks = Environment.TickCount; lastStop = Stopwatch.GetTimestamp(); lastRun = Time.realtimeSinceStartup; lastReal = Time.realtimeSinceStartup; } void Update () { var time = Time.realtimeSinceStartup; if (time - lastRun < 1) return; lastRun = time; var currTicks = Environment.TickCount; var currStop = Stopwatch.GetTimestamp(); var currReal = Time.realtimeSinceStartup; UnityEngine.Debug.Log(string.Format("{0} TICKS={1:0.0} WATCH={2:0.0} REAL={3:0.0}", DateTime.UtcNow, (currTicks - lastTicks) / 1000f, (currStop - lastStop) / 1000f / 10000f, -
webcoyote revised this gist
Jun 10, 2015 . 1 changed file with 6 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,19 +8,13 @@ public class Main : MonoBehaviour { int lastTicks; long lastStop; long lastRun; float lastReal; void Start () { lastTicks = Environment.TickCount; lastStop = Stopwatch.GetTimestamp(); lastRun = Stopwatch.GetTimestamp(); lastReal = Time.realtimeSinceStartup; } void Update () { @@ -31,17 +25,16 @@ void Update () { var currTicks = Environment.TickCount; var currStop = Stopwatch.GetTimestamp(); var currReal = Time.realtimeSinceStartup; UnityEngine.Debug.Log(string.Format("{0} {1:0.0} {2:0.0} {3:0.0}", DateTime.UtcNow, (currTicks - lastTicks) / 1000f, (currStop - lastStop) / 1000f / 10000f, (currReal - lastReal) )); lastTicks = currTicks; lastStop = currStop; lastReal = currReal; } } -
webcoyote revised this gist
Jun 10, 2015 . 1 changed file with 40 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,47 @@ using UnityEngine; using System; using System.Threading; using System.Diagnostics; using System.Runtime.InteropServices; public class Main : MonoBehaviour { int lastTicks; long lastStop; long lastRun; long lastQpc; [DllImport("KERNEL32")] private static extern bool QueryPerformanceCounter (out long lpPerformanceCount); [DllImport("Kernel32.dll")] private static extern bool QueryPerformanceFrequency (out long lpFrequency); void Start () { lastTicks = Environment.TickCount; lastStop = Stopwatch.GetTimestamp(); lastRun = Stopwatch.GetTimestamp(); QueryPerformanceCounter(out lastQpc); } void Update () { var time = Stopwatch.GetTimestamp(); if (time - lastRun < 1 * 1000 * 10000) return; lastRun = time; var currTicks = Environment.TickCount; var currStop = Stopwatch.GetTimestamp(); long currQpc; QueryPerformanceCounter(out currQpc); UnityEngine.Debug.Log(string.Format("{0} {1:0.0} {2:0.0} {3:0.0} {4}", DateTime.UtcNow, (currTicks - lastTicks) / 1000f, (currStop - lastStop) / 1000f / 10000f, (currQpc - lastQpc) / 1000f / 10000f, Stopwatch.IsHighResolution )); lastTicks = currTicks; lastStop = currStop; lastQpc = currQpc; } } -
webcoyote created this gist
Jun 10, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ using System; using System.Net; using System.Threading; using System.Diagnostics; public static class Program { public static void Main (string[] args) { var lastTicks = Environment.TickCount; var lastStop = Stopwatch.GetTimestamp(); while (true) { System.Threading.Thread.Sleep(5000); var currTicks = Environment.TickCount; var currStop = Stopwatch.GetTimestamp(); System.Console.WriteLine( "{0} {1:0.0} {2:0.0}", DateTime.UtcNow, (currTicks - lastTicks) / 1000f, (currStop - lastStop) / 1000f / 10000f ); lastTicks = currTicks; lastStop = currStop; } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ #!/bin/bash set -e # crash on errors set -u # crash on undefined variables set -o pipefail # crash when intermediate program in pipe fails SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" mcs "$SCRIPT_DIR/timer.cs" "$@"