How to measure execution time of function in golang, excluding waiting time
Two ways from StackOverflow Builtin Way Using “syscall” func GetCPU() int64 { usage := new(syscall.Rusage) syscall.Getrusage(syscall.RUSAGE_SELF, usage) return usage.Utime.Nano() + usage.Stime.Nano() } Explanation Utime: user CPU time Stime: system CPU time RUSAGE_SELF: means it’s measuring the “calling” process man 2 getrusage for more information NOTE: The documentation for syscall.Timeval suggests that Nano() returns the time in nanoseconds since the Unix epoch, but in my tests and looking at the implementation it appears actually to return just the CPU time in nanoseconds, not in nanoseconds since the Unix epoch. ...