From 13ce75261f2d4eda931f3de7b8c14dc7a56843a3 Mon Sep 17 00:00:00 2001 From: Tyler Bunnell Date: Tue, 20 May 2014 08:28:38 -0600 Subject: [PATCH] More comprehensive benchmarking --- context_test.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/context_test.go b/context_test.go index 36975d7..6ada8ec 100644 --- a/context_test.go +++ b/context_test.go @@ -104,14 +104,11 @@ func parallelWriter(r *http.Request, key, value string, iterations int, wait, do } -func BenchmarkMutex(b *testing.B) { +func benchmarkMutex(b *testing.B, numReaders, numWriters, iterations int) { b.StopTimer() r, _ := http.NewRequest("GET", "http://localhost:8080/", nil) done := make(chan struct{}) - numWriters := 64 - numReaders := numWriters * 8 - iterations := 128 b.StartTimer() for i := 0; i < b.N; i++ { @@ -134,3 +131,31 @@ func BenchmarkMutex(b *testing.B) { } } + +func BenchmarkMutexSameReadWrite1(b *testing.B) { + benchmarkMutex(b, 1, 1, 32) +} +func BenchmarkMutexSameReadWrite2(b *testing.B) { + benchmarkMutex(b, 2, 2, 32) +} +func BenchmarkMutexSameReadWrite4(b *testing.B) { + benchmarkMutex(b, 4, 4, 32) +} +func BenchmarkMutex1(b *testing.B) { + benchmarkMutex(b, 2, 8, 32) +} +func BenchmarkMutex2(b *testing.B) { + benchmarkMutex(b, 16, 4, 64) +} +func BenchmarkMutex3(b *testing.B) { + benchmarkMutex(b, 1, 2, 128) +} +func BenchmarkMutex4(b *testing.B) { + benchmarkMutex(b, 128, 32, 256) +} +func BenchmarkMutex5(b *testing.B) { + benchmarkMutex(b, 1024, 2048, 64) +} +func BenchmarkMutex6(b *testing.B) { + benchmarkMutex(b, 2048, 1024, 512) +}