Skip to content

Instantly share code, notes, and snippets.

@TomoG29
Last active January 13, 2019 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomoG29/1ff12608b19855da809fb2cb94e44e46 to your computer and use it in GitHub Desktop.
Save TomoG29/1ff12608b19855da809fb2cb94e44e46 to your computer and use it in GitHub Desktop.
private const uint Count = 10;// 100 , 1000
void Start()
{
TimeMeasurement(MaesurementProcess1, "Sample1",100);
TimeMeasurement(MaesurementProcess2, "Sample2",100);
}
private void MaesurementProcess1()
{
for(int i = 0; i < Count; i++)
{
PlayerPrefs.SetInt("Test", UnityEngine.Random.Range(0,100));
PlayerPrefs.Save();
}
}
private void MaesurementProcess2()
{
for(int i = 0; i < Count; i++)
{
PlayerPrefs.SetInt("Test", UnityEngine.Random.Range(0, 100));
}
PlayerPrefs.Save();
}
private void TimeMeasurement(Action action, string Tag)
{
_TimeMeasurement(action, Tag + " : ", 1);
}
private void TimeMeasurement(Action action, uint count)
{
_TimeMeasurement(action, "", count);
}
private void TimeMeasurement(Action action, string Tag, uint count)
{
_TimeMeasurement(action, Tag + " : ", count);
}
private void _TimeMeasurement(Action action, string Tag, uint count)
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
float num = 0;
for (int i = 0; i < count; i++)
{
sw.Start();
action();
sw.Stop();
float progress = (float)sw.Elapsed.TotalMilliseconds;
//Debug.Log(i.ToString() + "Time : " +progress.ToString());
num += progress;
sw.Reset();
}
Debug.Log(" num : " + num.ToString());
Debug.Log("Average : " + (num / count).ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment