Last active
August 6, 2021 11:39
-
-
Save percybolmer/49dd10726ae26e33e74d5743f48dab8f to your computer and use it in GitHub Desktop.
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) | |
// 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 | |
} | |
} | |
// BenchmarkInsertInterfaceMap1000000 benchmarks the speed of inserting 1000000 integers into the map. | |
func BenchmarkInsertInterfaceMap1000000(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
insertXInterfaceMap(1000000, b) | |
} | |
} | |
// BenchmarkInsertInterfaceMap100000 benchmarks the speed of inserting 100000 integers into the map. | |
func BenchmarkInsertInterfaceMap100000(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
insertXInterfaceMap(100000, b) | |
} | |
} | |
// BenchmarkInsertInterfaceMap10000 benchmarks the speed of inserting 10000 integers into the map. | |
func BenchmarkInsertInterfaceMap10000(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
insertXInterfaceMap(10000, b) | |
} | |
} | |
// BenchmarkInsertInterfaceMap1000 benchmarks the speed of inserting 1000 integers into the map. | |
func BenchmarkInsertInterfaceMap1000(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
insertXInterfaceMap(1000, b) | |
} | |
} | |
// BenchmarkInsertInterfaceMap100 benchmarks the speed of inserting 100 integers into the map. | |
func BenchmarkInsertInterfaceMap100(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
insertXInterfaceMap(100, b) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment