Open GeertvanHorrik opened 11 months ago
I suppose you'd like to get rid of the allocation? I'd just use Stopwatch.GetTimestamp()
and compare the ticks at the end - basically what ValueStopwatch
does. Also, ValueStopwatch
is internal.
Interesting comment, great observations. I can refactor so it replaces the StartNew by getting the timestamp and calculate the difference manually. Only thing to take into account is to convert the ticks to timespan, but that can be a 1-time static thing.
I just cloned the repository, and noticed that @SimonCropp already started a branch for this earlier this year. Not sure why it was finished, but happy to finalize the branch if needed.
Source code is available here:
https://github.com/dotnet/aspnetcore/blob/main/src/Shared/ValueStopwatch/ValueStopwatch.cs
This fody addon could check for the availability of the ValueStopwatch. If it exists, use it instead of Stopwatch.
Happy to PR if this is considered a good idea.