This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package benching | |
import ( | |
"testing" | |
) | |
func BenchmarkSimplest(b *testing.B) { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// B is a type passed to Benchmark functions to manage benchmark | |
// timing and to specify the number of iterations to run. | |
// | |
// A benchmark ends when its Benchmark function returns or calls any of the methods | |
// FailNow, Fatal, Fatalf, SkipNow, Skip, or Skipf. Those methods must be called | |
// only from the goroutine running the Benchmark function. | |
// The other reporting methods, such as the variations of Log and Error, | |
// may be called simultaneously from multiple goroutines. | |
// | |
// Like in tests, benchmark logs are accumulated during execution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BenchmarkSimplestNTimes runs a benchmark N amount of times. | |
func BenchmarkSimplestNTimes(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
// Run function to benchmark here | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// insertXIntMap is used to add X amount of items into a Map[int]int | |
func insertXIntMap(x int, b *testing.B) { | |
// Initialize Map and Insert X amount of items | |
testmap := make(map[int]int, 0) | |
// Reset timer after Initalizing map, that's not what we want to test | |
b.ResetTimer() | |
for i := 0; i < x; i++ { | |
// Insert value of I into I key. | |
testmap[i] = i | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BenchmarkInsertIntMap100000 benchmarks the speed of inserting 100000 integers into the map. | |
func BenchmarkInsertIntMap100000(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
insertXIntMap(100000, b) | |
} | |
} | |
// BenchmarkInsertIntMap10000 benchmarks the speed of inserting 10000 integers into the map. | |
func BenchmarkInsertIntMap10000(b *testing.B) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package benching | |
import ( | |
"testing" | |
) | |
// insertXInterfaceMap is used to add X amount of items into a Map[interface]int | |
func insertXInterfaceMap(x int, b *testing.B) { | |
// Initialize Map and Insert X amount of items | |
testmap := make(map[interface{}]int, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// insertXPreallocIntMap is used to add X amount of items into a Map[int]int | |
func insertXPreallocIntMap(x int, b *testing.B) { | |
// Initialize Map and Insert X amount of items and Prealloc the size to X | |
testmap := make(map[int]int, x) | |
// Reset timer after Initalizing map, that's not what we want to test | |
b.ResetTimer() | |
for i := 0; i < x; i++ { | |
// Insert value of I into I key. | |
testmap[i] = i | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package benching | |
import ( | |
"testing" | |
) | |
// insertXPreallocIntMap is used to add X amount of items into a Map[int]int | |
func insertXPreallocIntMap(x int, b *testing.B) { | |
// Initialize Map and Insert X amount of items and Prealloc the size to X | |
testmap := make(map[int]int, x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// insertXIntSlice is used to add X amount of items into a []int | |
func insertXIntSlice(x int, b *testing.B) { | |
// Initalize a Slice and insert X amount of Items | |
testSlice := make([]int, 0) | |
// reset timer | |
b.ResetTimer() | |
for i := 0; i < x; i++ { | |
testSlice = append(testSlice, i) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// insertXPreallocIntSlice is used to add X amount of items into a []int | |
func insertXPreallocIntSlice(x int, b *testing.B) { | |
// Initalize a Slice and insert X amount of Items | |
testSlice := make([]int, x) | |
// reset timer | |
b.ResetTimer() | |
for i := 0; i < x; i++ { | |
testSlice[i] = i | |
} | |
} |