Skip to content

Commit

Permalink
remove restriction of 10 alleles max in multiallelic sites (#11)
Browse files Browse the repository at this point in the history
* remove restriction of 10 alleles max in multiallelic sites

* fix haploid with allele > 9, add test

* improve strictness of bi-allelic check, add clarifying comments

* rune comparison is 15-20x faster than string, even with casts

* add go.mod and go.sum
  • Loading branch information
akotlar authored Jan 9, 2024
1 parent d0fda39 commit 6c736a2
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 205 deletions.
113 changes: 113 additions & 0 deletions benchmarks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
}
}
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/bystrogenomics/bystro-vcf

go 1.20

require github.com/akotlar/bystro-utils v0.0.0-20180921004542-b5183a523f20
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/akotlar/bystro-utils v0.0.0-20180921004542-b5183a523f20 h1:DTPJA8O7qs7Dc+YRg9wZusDy/SoVHqn9udRQlr+TSFA=
github.com/akotlar/bystro-utils v0.0.0-20180921004542-b5183a523f20/go.mod h1:BHUTiQAFM7OSW8+09I/OwWMhgbsonqQ6J8jTlnpOPnk=
Loading

0 comments on commit 6c736a2

Please # to comment.