logoalt Hacker News

antonvstoday at 4:24 PM1 replyview on HN

The point of the OP is that it changes calls to `time.Now` regardless of whether the code that's calling it uses your variable or not.


Replies

Groxxtoday at 4:57 PM

I suspect that using a build tag (say `test`) and two function definitions (one that directly calls `time.Now()` and one test-only one that uses a mutable var) will optimize out to zero cost in the non-test case - last I fiddled with that, it was pretty good at consistently inlining trivial wrapper funcs like that.

show 2 replies