MCPcopy Index your code
hub / github.com/coder/coder / BenchmarkGraph_ConcurrentMixedOperations

Function BenchmarkGraph_ConcurrentMixedOperations

agent/unit/graph_test.go:412–452  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

410}
411
412func BenchmarkGraph_ConcurrentMixedOperations(b *testing.B) {
413 graph := &testGraph{}
414 var wg sync.WaitGroup
415 const numGoroutines = 200
416
417 b.ResetTimer()
418 for i := 0; i < b.N; i++ {
419 // Launch goroutines performing random operations
420 for j := 0; j < numGoroutines; j++ {
421 wg.Add(1)
422 go func(goroutineID int) {
423 defer wg.Done()
424 operationCount := 0
425
426 for operationCount < 50 {
427 operation := float32(randInt(100)) / 100.0
428
429 if operation < 0.6 { // 60% reads
430 // Read operation
431 testUnit := &testGraphVertex{Name: fmt.Sprintf("bench-read-%d-%d", goroutineID, operationCount)}
432 forwardEdges := graph.GetForwardAdjacentVertices(testUnit)
433 reverseEdges := graph.GetReverseAdjacentVertices(testUnit)
434
435 // Just verify no panics (results may be nil for non-existent vertices)
436 _ = forwardEdges
437 _ = reverseEdges
438 } else { // 40% writes
439 // Write operation
440 from := &testGraphVertex{Name: fmt.Sprintf("bench-write-%d-%d", goroutineID, operationCount)}
441 to := &testGraphVertex{Name: fmt.Sprintf("bench-write-target-%d-%d", goroutineID, operationCount)}
442 graph.AddEdge(from, to, testEdgeCompleted)
443 }
444
445 operationCount++
446 }
447 }(j)
448 }
449
450 wg.Wait()
451 }
452}

Callers

nothing calls this directly

Calls 7

randIntFunction · 0.85
AddEdgeMethod · 0.80
AddMethod · 0.65
WaitMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected