mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
b942136a4a
With "some" help from `golangci-lint run --fix ./...` Signed-off-by: Anders Eknert <anders@styra.com>
49 lines
1009 B
Go
49 lines
1009 B
Go
// Copyright 2019 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package topdown
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/open-policy-agent/opa/v1/ast"
|
|
)
|
|
|
|
func BenchmarkVirtualCache(b *testing.B) {
|
|
|
|
n := 10
|
|
max := n * n * n
|
|
|
|
keys := make([]ast.Ref, 0, max)
|
|
values := make([]*ast.Term, 0, max)
|
|
|
|
for i := range n {
|
|
k1 := ast.StringTerm(fmt.Sprintf("aaaa%v", i))
|
|
for j := range n {
|
|
k2 := ast.StringTerm(fmt.Sprintf("bbbb%v", j))
|
|
for k := range n {
|
|
k3 := ast.StringTerm(fmt.Sprintf("cccc%v", k))
|
|
key := ast.Ref{ast.DefaultRootDocument, k1, k2, k3}
|
|
value := ast.ArrayTerm(k1, k2, k3)
|
|
keys = append(keys, key)
|
|
values = append(values, value)
|
|
}
|
|
}
|
|
}
|
|
|
|
cache := NewVirtualCache()
|
|
b.ResetTimer()
|
|
|
|
for i := range b.N {
|
|
idx := i % max
|
|
cache.Put(keys[idx], values[idx])
|
|
result, _ := cache.Get(keys[idx])
|
|
if !result.Equal(values[idx]) {
|
|
b.Fatal("expected equal")
|
|
}
|
|
}
|
|
|
|
}
|