github.com/zhongdalu/gf@v1.0.0/g/container/glist/glist_z_bench_test.go (about)

     1  // Copyright 2018 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  // go test *.go -bench=".*" -benchmem
     8  
     9  package glist
    10  
    11  import (
    12  	"testing"
    13  )
    14  
    15  var (
    16  	l = New()
    17  )
    18  
    19  func Benchmark_PushBack(b *testing.B) {
    20  	b.RunParallel(func(pb *testing.PB) {
    21  		i := 0
    22  		for pb.Next() {
    23  			l.PushBack(i)
    24  			i++
    25  		}
    26  	})
    27  }
    28  
    29  func Benchmark_PushFront(b *testing.B) {
    30  	b.RunParallel(func(pb *testing.PB) {
    31  		i := 0
    32  		for pb.Next() {
    33  			l.PushFront(i)
    34  			i++
    35  		}
    36  	})
    37  }
    38  
    39  func Benchmark_Len(b *testing.B) {
    40  	b.RunParallel(func(pb *testing.PB) {
    41  		for pb.Next() {
    42  			l.Len()
    43  		}
    44  	})
    45  }
    46  
    47  func Benchmark_PopFront(b *testing.B) {
    48  	b.RunParallel(func(pb *testing.PB) {
    49  		for pb.Next() {
    50  			l.PopFront()
    51  		}
    52  	})
    53  }
    54  
    55  func Benchmark_PopBack(b *testing.B) {
    56  	b.RunParallel(func(pb *testing.PB) {
    57  		for pb.Next() {
    58  			l.PopBack()
    59  		}
    60  	})
    61  }