I run the GO program (1.9.2), and I have code similar to:
startTime := time.Now()
...
...
fmt.Printf("%v (1) %v \n", user.uid, int64(time.Since(startTime)))
fmt.Printf("%v (F) %v \n", user.uid, int64(time.Since(startTime)))
(Two fmt statements are on consecutive lines)
I expected the printout to be similar to time, but here are some print results:
921 (1) 2000100
921 (F) 3040173800
(3 seconds)
360 (1) 2000100
360 (F) 1063060800
(1 second)
447 (1) 4000200
447 (F) 2564146700
(2.5 seconds)
The time difference between the two printouts is always high.
What could be the explanation for this phenomenon?
Additional information: According to pprof, at the time of printing ~ 15,000 goroutines are working, but most of them are waiting for incoming data in sockets.
I ran the code with GODEBUG=gctrace=1
, but not many GC prints, and not as many as the number of prints of my code.
EDIT:
It seems to save the result of time. Since () in the variables suggested by @Verran solves the problem.
fmt
log
, .
, "" , fmt
. , - , .