From d7a14041ebc24b7c94d1791c28a006a0e82386ec Mon Sep 17 00:00:00 2001 From: Urko Date: Sat, 8 Apr 2023 22:10:09 +0200 Subject: [PATCH] feat: improve benchmark --- benchmark/benchmark_test.go | 8 ++++---- benchmark/go/go.go | 9 ++++++++- benchmark/nest/nest.go | 10 +++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/benchmark/benchmark_test.go b/benchmark/benchmark_test.go index f321b4d..ab3c28c 100644 --- a/benchmark/benchmark_test.go +++ b/benchmark/benchmark_test.go @@ -26,7 +26,7 @@ func BenchmarkGo(b *testing.B) { log.SetOutput(f) for i := 0; i < b.N; i++ { - assert.NoError(b, go_benchmark.Benchmark(1, false)) + assert.NoError(b, go_benchmark.BenchmarkNoLog(1)) } } @@ -42,7 +42,7 @@ func BenchmarkNest(b *testing.B) { log.SetOutput(f) for i := 0; i < b.N; i++ { - assert.NoError(b, nest_benchmark.Benchmark(1, false)) + assert.NoError(b, nest_benchmark.BenchmarkNoLog(1)) } } @@ -58,7 +58,7 @@ func TestGoXRequestes(t *testing.T) { log.SetOutput(f) totalRequests := 1000 - require.NoError(t, go_benchmark.Benchmark(totalRequests, true)) + require.NoError(t, go_benchmark.Benchmark(totalRequests)) require.NoError(t, os.RemoveAll("./temp")) } @@ -73,5 +73,5 @@ func TestNestXRequests(t *testing.T) { log.SetOutput(f) totalRequests := 1000 - require.NoError(t, nest_benchmark.Benchmark(totalRequests, true)) + require.NoError(t, nest_benchmark.Benchmark(totalRequests)) } diff --git a/benchmark/go/go.go b/benchmark/go/go.go index 88c446d..4501e37 100644 --- a/benchmark/go/go.go +++ b/benchmark/go/go.go @@ -44,7 +44,14 @@ func doRequest(wg *sync.WaitGroup, host, employeeID string, errChan chan error) return nil } -func Benchmark(totalRequests int, dolog bool) error { +func BenchmarkNoLog(totalRequests int) error { + return benchmark(totalRequests, false) +} +func Benchmark(totalRequests int) error { + return benchmark(totalRequests, true) +} + +func benchmark(totalRequests int, dolog bool) error { cr := crono.New() if dolog { defer cr.Table() diff --git a/benchmark/nest/nest.go b/benchmark/nest/nest.go index ca91609..b2bd182 100644 --- a/benchmark/nest/nest.go +++ b/benchmark/nest/nest.go @@ -70,7 +70,15 @@ func doRequest(wg *sync.WaitGroup, host string, employeeID int, errChan chan err return nil } -func Benchmark(totalRequests int, dolog bool) error { +func BenchmarkNoLog(totalRequests int) error { + return benchmark(totalRequests, false) +} + +func Benchmark(totalRequests int) error { + return benchmark(totalRequests, true) +} + +func benchmark(totalRequests int, dolog bool) error { cr := crono.New() if dolog { defer cr.Table()