Fody / MethodTimer

Injects some very basic method timing code.
MIT License
718 stars 69 forks source link

Consider using ValueStopWatch #575

Open GeertvanHorrik opened 11 months ago

GeertvanHorrik commented 11 months ago

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.

ltrzesniewski commented 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.

GeertvanHorrik commented 11 months ago

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.

GeertvanHorrik commented 11 months ago

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.