BenchmarkRequestCollection tests the performance of request collection
(b *testing.B)
| 98 | |
| 99 | // BenchmarkRequestCollection tests the performance of request collection |
| 100 | func BenchmarkRequestCollection(b *testing.B) { |
| 101 | ctx := context.Background() |
| 102 | checker := &MockChecker{} |
| 103 | |
| 104 | config := BulkCheckerConfig{ |
| 105 | ConcurrencyLimit: 10, |
| 106 | BufferSize: 10000, |
| 107 | } |
| 108 | |
| 109 | callback := func(id, ct string) {} |
| 110 | |
| 111 | b.ResetTimer() |
| 112 | b.ReportAllocs() |
| 113 | |
| 114 | for b.Loop() { |
| 115 | bc, err := NewBulkChecker(ctx, checker, BulkCheckerTypeEntity, callback, config) |
| 116 | if err != nil { |
| 117 | b.Fatal(err) |
| 118 | } |
| 119 | |
| 120 | publisher := NewBulkEntityPublisher(ctx, &base.PermissionLookupEntityRequest{ |
| 121 | TenantId: "test", |
| 122 | Metadata: &base.PermissionLookupEntityRequestMetadata{}, |
| 123 | EntityType: "document", |
| 124 | Permission: "read", |
| 125 | Subject: &base.Subject{Id: "user1"}, |
| 126 | }, bc) |
| 127 | |
| 128 | // Publish requests rapidly |
| 129 | for j := 0; j < 10000; j++ { |
| 130 | publisher.Publish( |
| 131 | &base.Entity{Id: fmt.Sprintf("doc%d", j)}, |
| 132 | &base.PermissionCheckRequestMetadata{}, |
| 133 | &base.Context{}, |
| 134 | base.CheckResult_CHECK_RESULT_UNSPECIFIED, |
| 135 | ) |
| 136 | } |
| 137 | |
| 138 | bc.StopCollectingRequests() |
| 139 | bc.Close() |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // BenchmarkSorting tests the performance of request sorting |
| 144 | func BenchmarkSorting(b *testing.B) { |
nothing calls this directly
no test coverage detected