Last active
August 29, 2015 14:22
-
-
Save webcoyote/a0e11799a91a2d967083 to your computer and use it in GitHub Desktop.
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 characters
| #!/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" "$@" |
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 characters
| 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; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment