github.com/antlabs/stl@v0.0.1/list/list_benchmark_test.go (about)

     1  package list
     2  
     3  import (
     4  	"container/list"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  type timeNodeStdlib struct {
    10  	expire     uint64
    11  	userExpire time.Duration
    12  	callback   func()
    13  	isSchedule bool
    14  	close      uint32
    15  	lock       uint32
    16  }
    17  
    18  type timeNode struct {
    19  	expire     uint64
    20  	userExpire time.Duration
    21  	callback   func()
    22  	isSchedule bool
    23  	close      uint32
    24  	lock       uint32
    25  
    26  	Head
    27  }
    28  
    29  func Benchmark_ListAdd_Stdlib(b *testing.B) {
    30  	head := list.New()
    31  	for i := 0; i < b.N; i++ {
    32  		node := timeNodeStdlib{}
    33  		head.PushBack(node)
    34  	}
    35  }
    36  
    37  func Benchmark_ListAdd(b *testing.B) {
    38  	head := timeNode{}
    39  	head.Init()
    40  
    41  	for i := 0; i < b.N; i++ {
    42  		node := timeNode{}
    43  		head.AddTail(&node.Head)
    44  	}
    45  }