Simplify and optimize util.TimeTrack #4924
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Issue
The util.TimeTrack() function has currently a parameter start which was always set to time.Now() and can therefor set directly in the function instead which will reduce the impact a bit and simplify the usage. Also in many cases the name parameter was manually set to the calling function name which is also error prone.
With this patch, the TimeTrack functionallity was moved to a dedicated file in the same package and two functions are now available, one without parameters where the calling function name is retrieved with the help of the runtime package and a second with a name parameter to individually set a name e.g. used for tests. Source documentation was extended to also show a simpler one line usage which is apropriate in most cases. Also some minor optimization are done like avoiding the expensive format functions e.g. Printf. Finally the outputed messages are streamlined to increase visibility.