github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/runtime/malloc_test.go (about)

     1  // Copyright 2013 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 runtime_test
     6  
     7  import (
     8  	"testing"
     9  	"unsafe"
    10  )
    11  
    12  var mallocSink uintptr
    13  
    14  func BenchmarkMalloc8(b *testing.B) {
    15  	var x uintptr
    16  	for i := 0; i < b.N; i++ {
    17  		p := new(int64)
    18  		x ^= uintptr(unsafe.Pointer(p))
    19  	}
    20  	mallocSink = x
    21  }
    22  
    23  func BenchmarkMalloc16(b *testing.B) {
    24  	var x uintptr
    25  	for i := 0; i < b.N; i++ {
    26  		p := new([2]int64)
    27  		x ^= uintptr(unsafe.Pointer(p))
    28  	}
    29  	mallocSink = x
    30  }
    31  
    32  func BenchmarkMallocTypeInfo8(b *testing.B) {
    33  	var x uintptr
    34  	for i := 0; i < b.N; i++ {
    35  		p := new(struct {
    36  			p [8 / unsafe.Sizeof(uintptr(0))]*int
    37  		})
    38  		x ^= uintptr(unsafe.Pointer(p))
    39  	}
    40  	mallocSink = x
    41  }
    42  
    43  func BenchmarkMallocTypeInfo16(b *testing.B) {
    44  	var x uintptr
    45  	for i := 0; i < b.N; i++ {
    46  		p := new(struct {
    47  			p [16 / unsafe.Sizeof(uintptr(0))]*int
    48  		})
    49  		x ^= uintptr(unsafe.Pointer(p))
    50  	}
    51  	mallocSink = x
    52  }