github.com/matrixorigin/matrixone@v1.2.0/pkg/objectio/location_test.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package objectio
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/container/types"
    21  )
    22  
    23  func getLocation(name ObjectName) Location {
    24  	extent := NewExtent(1, 1, 1, 1)
    25  	return BuildLocation(name, extent, 1, 1)
    26  }
    27  
    28  func BenchmarkDecode(b *testing.B) {
    29  	var location Location
    30  	uuid, _ := types.BuildUuid()
    31  	name := BuildObjectName(&uuid, 1)
    32  	b.Run("build", func(b *testing.B) {
    33  		b.ResetTimer()
    34  		for i := 0; i < b.N; i++ {
    35  			location = getLocation(name)
    36  		}
    37  	})
    38  	b.Run("GetName", func(b *testing.B) {
    39  		b.ResetTimer()
    40  		for i := 0; i < b.N; i++ {
    41  			location.Name().SegmentId()
    42  			location.Name().Num()
    43  			location.ID()
    44  		}
    45  	})
    46  	b.Log(location.Name().String())
    47  }
    48  
    49  func BenchmarkCheckSame(b *testing.B) {
    50  	uid, _ := types.BuildUuid()
    51  	fname := BuildObjectName(&uid, 0)
    52  	blkID := NewBlockid(&uid, 0, 0)
    53  	b.Run("is-same-obj", func(b *testing.B) {
    54  		b.ResetTimer()
    55  		for i := 0; i < b.N; i++ {
    56  			IsBlockInObject(blkID, &fname)
    57  		}
    58  	})
    59  	var segid Segmentid
    60  	b.Run("is-same-seg", func(b *testing.B) {
    61  		b.ResetTimer()
    62  		for i := 0; i < b.N; i++ {
    63  			IsEmptySegid(&segid)
    64  		}
    65  	})
    66  	var blkid types.Blockid
    67  	b.Run("is-same-blk", func(b *testing.B) {
    68  		b.ResetTimer()
    69  		for i := 0; i < b.N; i++ {
    70  			IsEmptyBlkid(&blkid)
    71  		}
    72  	})
    73  }