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)
|
||||
{
|
||||
Item = item;
|
||||
this.item = item;
|
||||
ticks = Stopwatch.GetTimestamp();
|
||||
}
|
||||
|
||||
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