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;
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,
(currReal - lastReal)
));
lastTicks = currTicks;
lastStop = currStop;
lastReal = currReal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment