Skip to content

Instantly share code, notes, and snippets.

@willbeason
Created May 25, 2022 18:01
Show Gist options
  • Save willbeason/9c8e2a570baeeee946f9f9c7fd26359e to your computer and use it in GitHub Desktop.
Save willbeason/9c8e2a570baeeee946f9f9c7fd26359e to your computer and use it in GitHub Desktop.
package local
import (
"context"
"fmt"
"testing"
rbacv1 "k8s.io/api/rbac/v1"
)
const (
// n is the number of Roles to add per
n = 1000
nRules = 100
)
func BenchmarkStorages_AddData(b *testing.B) {
role := rbacv1.Role{}
role.Rules = make([]rbacv1.PolicyRule, nRules)
for r := 0; r < nRules; r++ {
role.Rules[r] = rbacv1.PolicyRule{
Verbs: []string{rbacv1.VerbAll},
APIGroups: []string{rbacv1.APIGroupAll},
Resources: []string{fmt.Sprintf("foo%d", r)},
ResourceNames: []string{fmt.Sprintf("name%d", r)},
}
}
b.ResetTimer()
for i := 0; i < b.N; i += n {
b.StopTimer()
d, err := New()
if err != nil {
b.Fatal(err)
}
ctx := context.Background()
b.StartTimer()
for j := 0; j < n; j++ {
err := d.AddData(ctx, "foo", []string{"rule", fmt.Sprintf("role-%d", j)}, role)
if err != nil {
b.Fatal(err)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment