Performance and Benchmarking Basics
Benchmark Table
Go benchmarks produce rows that compare operations with numbers such as nanoseconds per operation.
Benchmark Table
benchmark_table.go
package main
import "fmt"
type BenchRow struct {
Name string
NsOp int
Allocs int
}
func main() {
var nsOp =
row := BenchRow{Name: "BenchmarkLookup", NsOp: nsOp, Allocs: 0}
fastEnough := row.NsOp <= 100
allocationFree := row.Allocs == 0
fmt.Println("name=", row.Name)
fmt.Println("ns_per_op=", row.NsOp)
fmt.Println("allocs=", row.Allocs)
fmt.Println("fast_enough=", fastEnough)
fmt.Println("allocation_free=", allocationFree)
}
package main
import "fmt"
type BenchRow struct {
Name string
NsOp int
Allocs int
}
func main() {
var nsOp =
row := BenchRow{Name: "BenchmarkLookup", NsOp: nsOp, Allocs: 0}
fastEnough := row.NsOp <= 100
allocationFree := row.Allocs == 0
fmt.Println("name=", row.Name)
fmt.Println("ns_per_op=", row.NsOp)
fmt.Println("allocs=", row.Allocs)
fmt.Println("fast_enough=", fastEnough)
fmt.Println("allocation_free=", allocationFree)
}
package main
import "fmt"
type BenchRow struct {
Name string
NsOp int
Allocs int
}
func main() {
var nsOp =
row := BenchRow{Name: "BenchmarkLookup", NsOp: nsOp, Allocs: 0}
fastEnough := row.NsOp <= 100
allocationFree := row.Allocs == 0
fmt.Println("name=", row.Name)
fmt.Println("ns_per_op=", row.NsOp)
fmt.Println("allocs=", row.Allocs)
fmt.Println("fast_enough=", fastEnough)
fmt.Println("allocation_free=", allocationFree)
}
benchmark result
Static examples can model benchmark output as data so the lesson explains interpretation without timing the host machine.