Test using Queue instead of List for Latency stats

The Queue version is faster
This commit is contained in:
Travis Nickles 2017-06-04 19:14:44 -07:00
parent 5c5e983ec1
commit e207114339

View File

@ -630,7 +630,8 @@ namespace DS4Windows
{ {
firstActive = DateTime.UtcNow; firstActive = DateTime.UtcNow;
NativeMethods.HidD_SetNumInputBuffers(hDevice.safeReadHandle.DangerousGetHandle(), 2); NativeMethods.HidD_SetNumInputBuffers(hDevice.safeReadHandle.DangerousGetHandle(), 2);
List<long> latencyList = new List<long>(51); // Set capacity at max + 1 to avoid any list resizing //List<long> latencyList = new List<long>(51); // Set capacity at max + 1 to avoid any list resizing
Queue<long> latencyQueue = new Queue<long>(51); // Set capacity at max + 1 to avoid any resizing
int tempLatencyCount = 0; int tempLatencyCount = 0;
long oldtime = 0; long oldtime = 0;
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
@ -643,17 +644,21 @@ namespace DS4Windows
string currerror = string.Empty; string currerror = string.Empty;
long curtime = sw.ElapsedMilliseconds; long curtime = sw.ElapsedMilliseconds;
this.lastTimeElapsed = curtime - oldtime; this.lastTimeElapsed = curtime - oldtime;
latencyList.Add(this.lastTimeElapsed); //latencyList.Add(this.lastTimeElapsed);
latencyQueue.Enqueue(this.lastTimeElapsed);
tempLatencyCount++; tempLatencyCount++;
oldtime = curtime; oldtime = curtime;
if (tempLatencyCount > 50) if (tempLatencyCount > 50)
{ {
latencyList.RemoveAt(0); //latencyList.RemoveAt(0);
latencyQueue.Dequeue();
tempLatencyCount--; tempLatencyCount--;
} }
Latency = latencyList.Average(); //Latency = latencyList.Average();
//latencyList.Average();
Latency = latencyQueue.Average();
if (conType == ConnectionType.BT) if (conType == ConnectionType.BT)
{ {