Исходники и презентации
This commit is contained in:
28
lessons/allocator/allocation_effect_3/allocation_test.go
Normal file
28
lessons/allocator/allocation_effect_3/allocation_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
// go test -bench=. -benchmem
|
||||
|
||||
type Data struct {
|
||||
pointer *int
|
||||
}
|
||||
|
||||
func BenchmarkIteration1(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var number int
|
||||
data := &Data{
|
||||
pointer: &number,
|
||||
}
|
||||
_ = data
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkIteration2(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var number int
|
||||
data := &Data{}
|
||||
data.pointer = &number
|
||||
_ = data
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user