【rich function】benchmark once function

This commit is contained in:
sunwei
2020-08-09 02:46:22 +08:00
committed by Kevin Wan
parent 1104363988
commit 945d59a980

View File

@@ -18,3 +18,15 @@ func TestOnce(t *testing.T) {
assert.Equal(t, 1, v)
}
func BenchmarkOnce(b *testing.B) {
var v int
add := Once(func() {
v++
})
b.ResetTimer()
for i:=0;i<b.N;i++{
add()
}
assert.Equal(b, 1, v)
}