github.com/raunakjodhawat/gorithims@v2.1.1+incompatible/src/dataStructure/collection/queue/queue_benchmark_test.go (about)

     1  package queue
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func BenchmarkQueue_Add(b *testing.B) {
     9  	q := Queue{}
    10  	for i := 0; i < b.N; i++ {
    11  		isAdded := q.Add(i)
    12  		if !isAdded {
    13  			fmt.Println("unable to add element to the queue")
    14  		}
    15  	}
    16  }
    17  
    18  func BenchmarkQueue_Element(b *testing.B) {
    19  	q := Queue{}
    20  	for i := 0; i < b.N; i++ {
    21  		_ = q.Element()
    22  	}
    23  }
    24  
    25  func BenchmarkQueue_IsEmpty(b *testing.B) {
    26  	q := Queue{}
    27  	for i := 0; i < b.N; i++ {
    28  		_ = q.IsEmpty()
    29  	}
    30  }
    31  
    32  func BenchmarkQueue_Offer(b *testing.B) {
    33  	q := Queue{}
    34  	for i := 0; i < b.N; i++ {
    35  		isAdded := q.Offer(i)
    36  		if !isAdded {
    37  			fmt.Println("unable to add element to the queue")
    38  		}
    39  	}
    40  }
    41  
    42  func BenchmarkQueue_Peek(b *testing.B) {
    43  	q := Queue{}
    44  	for i := 0; i < b.N; i++ {
    45  		_ = q.Peek()
    46  	}
    47  }
    48  
    49  func BenchmarkQueue_Poll(b *testing.B) {
    50  	q := Queue{}
    51  	for i := 0; i < b.N; i++ {
    52  		_, _ = q.Poll()
    53  	}
    54  }
    55  
    56  func BenchmarkQueue_Remove(b *testing.B) {
    57  	q := Queue{}
    58  	for i := 0; i < 10; i++ {
    59  		_, _ = q.Remove()
    60  	}
    61  }
    62  
    63  func BenchmarkQueue_Size(b *testing.B) {
    64  	q := Queue{}
    65  	for i := 0; i < b.N; i++ {
    66  		_ = q.Size()
    67  	}
    68  }