Debian Codegraph @

identity/finder_test.go

raw
1 // Copyright 2024 The Hugo Authors. All rights reserved.
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 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 // Package provides ways to identify values in Hugo. Used for dependency tracking etc.
15 package identity_test
16
17 import (
18 "testing"
19
20 "github.com/gohugoio/hugo/identity"
21 )
22
23 func BenchmarkFinder(b *testing.B) {
24 m1 := identity.NewManager()
25 m2 := identity.NewManager()
26 m3 := identity.NewManager()
27 m1.AddIdentity(
28 testIdentity{"base", "id1", "", "pe1"},
29 testIdentity{"base2", "id2", "eq1", ""},
30 m2,
31 m3,
32 )
33
34 b4 := testIdentity{"base4", "id4", "", ""}
35 b5 := testIdentity{"base5", "id5", "", ""}
36
37 m2.AddIdentity(b4)
38
39 f := identity.NewFinder(identity.FinderConfig{})
40
41 b.Run("Find one", func(b *testing.B) {
42 for b.Loop() {
43 r := f.Contains(b4, m1, -1)
44 if r == 0 {
45 b.Fatal("not found")
46 }
47 }
48 })
49
50 b.Run("Find none", func(b *testing.B) {
51 for b.Loop() {
52 r := f.Contains(b5, m1, -1)
53 if r > 0 {
54 b.Fatal("found")
55 }
56 }
57 })
58 }