tpl/collections: Add BenchmarkWhereOps - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit ef6e813ca8e185bfb9c629e76380647394cd296f
DIR parent f4598a09864bee2689a7630dda83a71a9b9cf55b
HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Fri, 28 Jul 2023 10:06:16 +0200
tpl/collections: Add BenchmarkWhereOps
```
BenchmarkWhereOps/eq-10 8702 120410 ns/op 52280 B/op 2515 allocs/op
BenchmarkWhereOps/ne-10 9829 120759 ns/op 52280 B/op 2515 allocs/op
BenchmarkWhereOps/like-10 6754 176377 ns/op 52917 B/op 2515 allocs/op
```
Diffstat:
M tpl/collections/where_test.go | 44 +++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+), 0 deletions(-)
---
DIR diff --git a/tpl/collections/where_test.go b/tpl/collections/where_test.go
@@ -17,6 +17,7 @@ import (
"context"
"fmt"
"html/template"
+ "math/rand"
"reflect"
"strings"
"testing"
@@ -859,3 +860,46 @@ func TestEvaluateSubElem(t *testing.T) {
}
}
}
+
+func BenchmarkWhereOps(b *testing.B) {
+ ns := newNs()
+ var seq []map[string]string
+ ctx := context.Background()
+ for i := 0; i < 500; i++ {
+ seq = append(seq, map[string]string{"foo": "bar"})
+ }
+ for i := 0; i < 500; i++ {
+ seq = append(seq, map[string]string{"foo": "baz"})
+ }
+ // Shuffle the sequence.
+ for i := range seq {
+ j := rand.Intn(i + 1)
+ seq[i], seq[j] = seq[j], seq[i]
+ }
+ //results, err = ns.Where(context.Background(), test.seq, test.key, test.op, test.match)
+ runOps := func(b *testing.B, op, match string) {
+ _, err := ns.Where(ctx, seq, "foo", op, match)
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+
+ b.Run("eq", func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ runOps(b, "eq", "bar")
+ }
+ })
+
+ b.Run("ne", func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ runOps(b, "ne", "baz")
+ }
+ })
+
+ b.Run("like", func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ runOps(b, "like", "^bar")
+ }
+ })
+
+}