-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmarks_test.go
113 lines (98 loc) · 2.68 KB
/
benchmarks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"testing"
)
// Benchmark for comparing a rune element with a rune variable
func BenchmarkRuneEquality(b *testing.B) {
// Sample rune slice and a rune variable to compare with
data := []rune{'a', 'b', 'c'}
compareRune := 'a'
b.ResetTimer() // Reset the timer to exclude setup time
for i := 0; i < b.N; i++ {
for _, r := range data {
if r == compareRune {
// Perform some action if equal
}
}
}
}
// Benchmark for comparing a rune element cast to a string with a string variable
func BenchmarkStringEquality(b *testing.B) {
// Sample rune slice and a string variable to compare with
data := []rune{'a', 'b', 'c'}
compareString := "a"
b.ResetTimer() // Reset the timer to exclude setup time
for i := 0; i < b.N; i++ {
for _, r := range data {
if string(r) == compareString {
// Perform some action if equal
}
}
}
}
func BenchmarkStringToRuneEquality(b *testing.B) {
// Sample rune slice and a string variable to compare with
data := []string{"a", "b", "c"}
compareRune := 'a'
b.ResetTimer() // Reset the timer to exclude setup time
for i := 0; i < b.N; i++ {
for _, r := range data {
if rune(r[0]) == compareRune {
// Perform some action if equal
}
}
}
}
func BenchmarkStringToStringEquality(b *testing.B) {
// Sample rune slice and a string variable to compare with
data := []string{"a", "b", "c"}
compareString := "a"
b.ResetTimer() // Reset the timer to exclude setup time
for i := 0; i < b.N; i++ {
for _, r := range data {
if string(r[0]) == compareString {
// Perform some action if equal
}
}
}
}
func BenchmarkGenotypeToStringEquality(b *testing.B) {
// Sample rune slice and a string variable to compare with
data := []string{"0|1", "1|0", "0|1"}
compareString := "0"
b.ResetTimer() // Reset the timer to exclude setup time
for i := 0; i < b.N; i++ {
for _, r := range data {
if string(r[0]) == compareString {
// Perform some action if equal
}
}
}
}
func BenchmarkGenotypeToRuneEquality(b *testing.B) {
// Sample rune slice and a string variable to compare with
data := []string{"0|1", "1|0", "0|1"}
compareString := "0"
b.ResetTimer() // Reset the timer to exclude setup time
for i := 0; i < b.N; i++ {
for _, r := range data {
if rune(r[0]) == rune(compareString[0]) {
// Perform some action if equal
}
}
}
}
func BenchmarkGenotypeToRuneEqualityWithLengthTest(b *testing.B) {
data := []string{"0|1", "1|0", "0|1"}
compareString := "0"
b.ResetTimer() // Reset the timer to exclude setup time
for i := 0; i < b.N; i++ {
if len(compareString) == 1 {
for _, r := range data {
if rune(r[0]) == rune(compareString[0]) {
// Perform some action if equal
}
}
}
}
}