...
Run Format

Source file src/testing/allocs_test.go

Documentation: testing

     1  // Copyright 2014 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 testing_test
     6  
     7  import "testing"
     8  
     9  var global interface{}
    10  
    11  var allocsPerRunTests = []struct {
    12  	name   string
    13  	fn     func()
    14  	allocs float64
    15  }{
    16  	{"alloc *byte", func() { global = new(*byte) }, 1},
    17  	{"alloc complex128", func() { global = new(complex128) }, 1},
    18  	{"alloc float64", func() { global = new(float64) }, 1},
    19  	{"alloc int32", func() { global = new(int32) }, 1},
    20  	{"alloc byte", func() { global = new(byte) }, 1},
    21  }
    22  
    23  func TestAllocsPerRun(t *testing.T) {
    24  	for _, tt := range allocsPerRunTests {
    25  		if allocs := testing.AllocsPerRun(100, tt.fn); allocs != tt.allocs {
    26  			t.Errorf("AllocsPerRun(100, %s) = %v, want %v", tt.name, allocs, tt.allocs)
    27  		}
    28  	}
    29  }
    30  

View as plain text