github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/posting/lmap_test.go (about)

     1  /*
     2   * Copyright 2015-2018 Dgraph Labs, Inc. and Contributors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package posting
    18  
    19  import (
    20  	"math/rand"
    21  	"testing"
    22  )
    23  
    24  func BenchmarkGet(b *testing.B) {
    25  	// lmap := NewMap(false)
    26  	var key []byte
    27  	b.RunParallel(func(pb *testing.PB) {
    28  		for pb.Next() {
    29  			// i := uint64(rand.Int63())
    30  			_ = uint64(rand.Int63())
    31  			getNew(key, nil)
    32  			// lmap.Get(i)
    33  		}
    34  	})
    35  }
    36  
    37  func BenchmarkGetLinear(b *testing.B) {
    38  	var key []byte
    39  	m := make(map[uint64]*List)
    40  	for i := 0; i < b.N; i++ {
    41  		k := uint64(i)
    42  		if _, ok := m[k]; !ok {
    43  			l, err := getNew(key, nil)
    44  			if err != nil {
    45  				b.Error(err)
    46  			}
    47  			m[k] = l
    48  		}
    49  	}
    50  }
    51  
    52  func BenchmarkGetLinearBool(b *testing.B) {
    53  	m := make(map[uint64]bool)
    54  	for i := 0; i < b.N; i++ {
    55  		k := uint64(i)
    56  		if _, ok := m[k]; !ok {
    57  			m[k] = true
    58  		}
    59  	}
    60  }