github.com/lovishpuri/go-40569/src@v0.0.0-20230519171745-f8623e7c56cf/os/exec/bench_test.go (about)

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package exec
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func BenchmarkExecHostname(b *testing.B) {
    12  	b.ReportAllocs()
    13  	path, err := LookPath("hostname")
    14  	if err != nil {
    15  		b.Fatalf("could not find hostname: %v", err)
    16  	}
    17  	b.ResetTimer()
    18  	for i := 0; i < b.N; i++ {
    19  		if err := Command(path).Run(); err != nil {
    20  			b.Fatalf("hostname: %v", err)
    21  		}
    22  	}
    23  }