Skip to content

Instantly share code, notes, and snippets.

@webcoyote
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save webcoyote/a0e11799a91a2d967083 to your computer and use it in GitHub Desktop.

Select an option

Save webcoyote/a0e11799a91a2d967083 to your computer and use it in GitHub Desktop.
#!/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" "$@"
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