private IEnumerator Poll() { var procCount = Environment.ProcessorCount; var prevSysTime = DateTime.Now; var prevCpuTime = GetCpuTime(); while (true) { yield return(new WaitForSeconds(pollingFrequency)); var currSysTime = DateTime.Now; var currCpuTime = GetCpuTime(); var sysTime = currSysTime - prevSysTime; var cpuTime = currCpuTime - prevCpuTime; var cpu = cpuTime * 100.0 / (procCount * sysTime.TotalMilliseconds); _history.Enqueue(cpu); if (tmpText) { tmpText.SetText($"CPU: {cpu:F1}% ({_history.Average():F1}%)"); } prevSysTime = currSysTime; prevCpuTime = currCpuTime; } }
public void StopBenchmark() { // if not active with frames, exit if (!(_active && _frames > 0)) { return; } // add to history _history.Enqueue(_frames); // log result Debug.Log($"[Benchmark] Score: {_frames}"); // calculate average _average = _history.Average(); // set as inactive _active = false; }
private IEnumerator Poll() { const float wait = 0.5f; while (true) { yield return(new WaitForSeconds(wait)); var fps = _frames / wait; _history.Enqueue(fps); if (tmpText) { tmpText.SetText($"FPS: {fps:F1} ({_history.Average():F1})"); } _frames = 0; } }