github.com/pure-x-eth/consensus_tm@v0.0.0-20230502163723-e3c2ff987250/libs/clist/bench_test.go (about)

     1  package clist
     2  
     3  import "testing"
     4  
     5  func BenchmarkDetaching(b *testing.B) {
     6  	lst := New()
     7  	for i := 0; i < b.N+1; i++ {
     8  		lst.PushBack(i)
     9  	}
    10  	start := lst.Front()
    11  	nxt := start.Next()
    12  	b.ResetTimer()
    13  	for i := 0; i < b.N; i++ {
    14  		start.removed = true
    15  		start.DetachNext()
    16  		start.DetachPrev()
    17  		tmp := nxt
    18  		nxt = nxt.Next()
    19  		start = tmp
    20  	}
    21  }
    22  
    23  // This is used to benchmark the time of RMutex.
    24  func BenchmarkRemoved(b *testing.B) {
    25  	lst := New()
    26  	for i := 0; i < b.N+1; i++ {
    27  		lst.PushBack(i)
    28  	}
    29  	start := lst.Front()
    30  	nxt := start.Next()
    31  	b.ResetTimer()
    32  	for i := 0; i < b.N; i++ {
    33  		start.Removed()
    34  		tmp := nxt
    35  		nxt = nxt.Next()
    36  		start = tmp
    37  	}
    38  }
    39  
    40  func BenchmarkPushBack(b *testing.B) {
    41  	lst := New()
    42  	b.ResetTimer()
    43  	for i := 0; i < b.N; i++ {
    44  		lst.PushBack(i)
    45  	}
    46  }