50 lines
840 B
Go
50 lines
840 B
Go
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()
|
|
}
|