I want to build a benchmarking tool similar to the unix tool time
. What I currently have is this:
package main
import (
"fmt"
"os"
"os/exec"
"time"
)
func main() {
command := os.Args[1]
args := os.Args[2:]
cmd := exec.Command(command, args...)
start_time := time.Now().UnixNano()
stdout, err := cmd.Output()
if err != nil {
println(err.Error())
return
}
print(string(stdout))
total_time := int64(time.Nanosecond) * (time.Now().UnixNano() - start_time) / int64(time.Millisecond)
fmt.Println(total_time)
}
My problem with this is, that the output is not streaming, instead it is printed all at once, and weirdly enough for some programs not at all.