2023-04-05 21:35:06 +02:00
|
|
|
package benchmark
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
go_benchmark "gitea.urkob.com/urko/ess-etl-go/benchmark/go"
|
|
|
|
nest_benchmark "gitea.urkob.com/urko/ess-etl-go/benchmark/nest"
|
2023-04-08 22:05:26 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-04-05 21:35:06 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-04-08 22:05:26 +02:00
|
|
|
func BenchmarkGo(b *testing.B) {
|
|
|
|
require.NoError(b, os.RemoveAll("./dump"))
|
|
|
|
require.NoError(b, os.MkdirAll("./dump", os.ModeTemporary))
|
|
|
|
log.SetFlags(log.Lmicroseconds)
|
|
|
|
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))
|
|
|
|
f, err := os.OpenFile("./dump/"+logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
log.SetOutput(f)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-04-08 22:10:09 +02:00
|
|
|
assert.NoError(b, go_benchmark.BenchmarkNoLog(1))
|
2023-04-08 22:05:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
func BenchmarkNest(b *testing.B) {
|
|
|
|
require.NoError(b, os.RemoveAll("./dump"))
|
|
|
|
require.NoError(b, os.MkdirAll("./dump", os.ModeTemporary))
|
|
|
|
log.SetFlags(log.Lmicroseconds)
|
|
|
|
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))
|
|
|
|
f, err := os.OpenFile("./dump/"+logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
|
|
|
|
require.NoError(b, err)
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
log.SetOutput(f)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-04-08 22:10:09 +02:00
|
|
|
assert.NoError(b, nest_benchmark.BenchmarkNoLog(1))
|
2023-04-08 22:05:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 21:35:06 +02:00
|
|
|
func TestGoXRequestes(t *testing.T) {
|
|
|
|
log.SetFlags(log.Lmicroseconds)
|
|
|
|
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))
|
|
|
|
err := os.MkdirAll("./dump", os.ModeTemporary)
|
|
|
|
require.NoError(t, err)
|
|
|
|
f, err := os.OpenFile("./dump/"+logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
log.SetOutput(f)
|
|
|
|
|
|
|
|
totalRequests := 1000
|
2023-04-08 22:10:09 +02:00
|
|
|
require.NoError(t, go_benchmark.Benchmark(totalRequests))
|
2023-04-05 21:35:06 +02:00
|
|
|
require.NoError(t, os.RemoveAll("./temp"))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNestXRequests(t *testing.T) {
|
|
|
|
log.SetFlags(log.Lmicroseconds)
|
|
|
|
logFileName := fmt.Sprintf("%s.txt", time.Now().Format(strings.ReplaceAll(time.RFC1123Z, ":", "_")))
|
|
|
|
f, err := os.OpenFile("./dump/"+logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
defer f.Close()
|
|
|
|
log.SetOutput(f)
|
|
|
|
|
|
|
|
totalRequests := 1000
|
2023-04-08 22:10:09 +02:00
|
|
|
require.NoError(t, nest_benchmark.Benchmark(totalRequests))
|
2023-04-05 21:35:06 +02:00
|
|
|
}
|