github.com/vuuihc/gocedar@v0.1.0/cedar_bm_test.go (about)

     1  package cedar
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	"github.com/vcaesar/tt"
     8  )
     9  
    10  func BenchmarkInsert(t *testing.B) {
    11  	cd := New(&Options{
    12  		Reduced: true,
    13  	})
    14  	fn := func() {
    15  		require.NoError(t, cd.Insert([]byte("a"), 1))
    16  		require.NoError(t, cd.Insert([]byte("b"), 3))
    17  		require.NoError(t, cd.Insert([]byte("d"), 6))
    18  	}
    19  
    20  	tt.BM(t, fn)
    21  }
    22  
    23  func BenchmarkJump(t *testing.B) {
    24  	fn := func() {
    25  		_, err := cd.Jump([]byte("a"), 1)
    26  		require.NoError(t, err)
    27  	}
    28  
    29  	tt.BM(t, fn)
    30  }
    31  
    32  func BenchmarkFind(t *testing.B) {
    33  	fn := func() {
    34  		_, err := cd.Find([]byte("a"), 1)
    35  		require.NoError(t, err)
    36  	}
    37  
    38  	tt.BM(t, fn)
    39  }
    40  
    41  func BenchmarkValue(t *testing.B) {
    42  	fn := func() {
    43  		_, err := cd.Value(1)
    44  		require.NoError(t, err)
    45  	}
    46  
    47  	tt.BM(t, fn)
    48  }
    49  
    50  func BenchmarkUpdate(t *testing.B) {
    51  	fn := func() {
    52  		require.NoError(t, cd.Update([]byte("a"), 1))
    53  	}
    54  
    55  	tt.BM(t, fn)
    56  }
    57  
    58  func BenchmarkDelete(t *testing.B) {
    59  	fn := func() {
    60  		require.NoError(t, cd.Delete([]byte("b")))
    61  	}
    62  
    63  	tt.BM(t, fn)
    64  }