feat: improve benchmark

This commit is contained in:
Urko 2023-04-08 22:10:09 +02:00
parent e48ad6108b
commit d7a14041eb
3 changed files with 21 additions and 6 deletions

View File

@ -26,7 +26,7 @@ func BenchmarkGo(b *testing.B) {
log.SetOutput(f) log.SetOutput(f)
for i := 0; i < b.N; i++ { 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) log.SetOutput(f)
for i := 0; i < b.N; i++ { 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) log.SetOutput(f)
totalRequests := 1000 totalRequests := 1000
require.NoError(t, go_benchmark.Benchmark(totalRequests, true)) require.NoError(t, go_benchmark.Benchmark(totalRequests))
require.NoError(t, os.RemoveAll("./temp")) require.NoError(t, os.RemoveAll("./temp"))
} }
@ -73,5 +73,5 @@ func TestNestXRequests(t *testing.T) {
log.SetOutput(f) log.SetOutput(f)
totalRequests := 1000 totalRequests := 1000
require.NoError(t, nest_benchmark.Benchmark(totalRequests, true)) require.NoError(t, nest_benchmark.Benchmark(totalRequests))
} }

View File

@ -44,7 +44,14 @@ func doRequest(wg *sync.WaitGroup, host, employeeID string, errChan chan error)
return nil 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() cr := crono.New()
if dolog { if dolog {
defer cr.Table() defer cr.Table()

View File

@ -70,7 +70,15 @@ func doRequest(wg *sync.WaitGroup, host string, employeeID int, errChan chan err
return nil 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() cr := crono.New()
if dolog { if dolog {
defer cr.Table() defer cr.Table()