some testing ang enchancments

This commit is contained in:
2026-02-06 13:46:09 +03:00
parent 948ac0a1b0
commit 4ba746956a
7 changed files with 286 additions and 94 deletions

49
queue_test.go Normal file
View File

@@ -0,0 +1,49 @@
package extypes
import (
"log"
"testing"
)
func ExampleCreateQueue() {
q := CreateQueue[int](16)
err := q.Enqueue(1)
if err != nil {
panic(err)
}
i := q.Dequeue() // <- Here we got 1
log.Println(i)
}
func BenchmarkQueue_Enqueue(b *testing.B) {
b.StartTimer()
q := CreateQueue[int](uint64(b.N))
for i := 0; i < b.N; i++ {
q.Enqueue(i)
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkQueue_Dequeue(b *testing.B) {
q := CreateQueue[int](uint64(b.N))
for i := 0; i < b.N; i++ {
q.Enqueue(i)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
q.Dequeue()
}
b.StopTimer()
b.ReportAllocs()
}
func BenchmarkQueue_EnqueueDequeue(b *testing.B) {
b.StartTimer()
q := CreateQueue[int](uint64(b.N))
for i := 0; i < b.N; i++ {
q.Enqueue(i)
}
for i := 0; i < b.N; i++ {
q.Dequeue()
}
b.StopTimer()
b.ReportAllocs()
}