new benchmarking method

This commit is contained in:
user_name 2024-03-03 08:44:42 -07:00
parent 3a88b108bb
commit 044e050f8f
3 changed files with 31 additions and 8 deletions

View File

@ -2,24 +2,42 @@ package main
import (
"log"
"sync"
"git.staur.ca/stobbsm/tind"
)
var (
longRuneSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}/';:.>,<`~"
shortRuneSet = "0123456789"
RuneSet = []rune("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}/';:.>,<`~")
)
const runs uint64 = 10000
// CollisionChecks runs different tests to check for collisions, and get's the average
func CollisionChecks() {
wg := new(sync.WaitGroup)
log.Println("Using multiple configurations, test for collisions multiple times")
for i := 0; i < 10; i++ {
log.Printf("Check %d", i)
log.Printf("Using default values, collision after %d iterations", runCheck(tind.Gen().Config()))
sizes := []int{4,5,6,7,8,9,10,11,12,13,14,15,16}
end := len(RuneSet)
for i := 4; i < end; i++ {
for _, v := range sizes {
v := v
rs :=RuneSet[:i]
wg.Add(1)
go collisionCheck(v, rs, wg, len(rs))
}
}
wg.Wait()
}
func collisionCheck(size int, runeset []rune, wg *sync.WaitGroup, runesize int) {
defer wg.Done()
var total uint64
for i := uint64(0); i < runs; i++ {
total += runCheck(tind.New().WithSize(size).WithRuneset(runeset))
}
log.Printf("runset size: %d, id size: %d, average iterations before collision: %d", runesize, size, total/runs)
}
func runCheck(tconfig *tind.Config) uint64 {

View File

@ -6,6 +6,7 @@ import (
"git.staur.ca/stobbsm/tind"
)
// GenWithDefaults demonstrates how to generate a TinD using the default configuration
func GenWithDefaults() {
fmt.Println("Generate 16 different TinD ID's, and print them in both string and byte representations using the default config")

View File

@ -3,5 +3,9 @@ package main
import "log"
func main() {
log.Println("Running the examples")
log.Println("Example: GenWithDefaults")
GenWithDefaults()
log.Println("Example: CollisionChecks")
CollisionChecks()
}