Streamline PerfSample.
- Avoid memory allocations by making PerfSample a struct, and tracking ticks manually rather than creating a Stopwatch instance.
This commit is contained in:
@@ -105,19 +105,20 @@ namespace OpenRA.Support
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class PerfSample : IDisposable
|
public struct PerfSample : IDisposable
|
||||||
{
|
{
|
||||||
readonly Stopwatch sw = Stopwatch.StartNew();
|
readonly string item;
|
||||||
readonly string Item;
|
readonly long ticks;
|
||||||
|
|
||||||
public PerfSample(string item)
|
public PerfSample(string item)
|
||||||
{
|
{
|
||||||
Item = item;
|
this.item = item;
|
||||||
|
ticks = Stopwatch.GetTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
PerfHistory.Increment(Item, sw.Elapsed.TotalMilliseconds);
|
PerfHistory.Increment(item, 1000.0 * Math.Max(0, Stopwatch.GetTimestamp() - ticks) / Stopwatch.Frequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user