mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
26 lines
377 B
Go
26 lines
377 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
var (
|
|
globalValue int
|
|
globalPtr *int
|
|
)
|
|
|
|
func BenchmarkSumValue(b *testing.B) {
|
|
b.ReportAllocs()
|
|
var local int
|
|
for i := 0; i < b.N; i++ {
|
|
local = sumValue(i, i)
|
|
}
|
|
globalValue = local
|
|
}
|
|
|
|
func BenchmarkSumPtr(b *testing.B) {
|
|
b.ReportAllocs()
|
|
var local *int
|
|
for i := 0; i < b.N; i++ {
|
|
local = sumPtr(i, i)
|
|
}
|
|
globalValue = *local
|
|
}
|