Skip to content

Commit

Permalink
feat: add a metric on bench
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored and flemzord committed May 12, 2023
1 parent cdb8963 commit 89e2fd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions benchmarks/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/formancehq/ledger/pkg/storage/sqlstorage/sqlstoragetesting"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
)

func BenchmarkParallelWrites(b *testing.B) {
Expand All @@ -40,6 +41,7 @@ func BenchmarkParallelWrites(b *testing.B) {

r := rand.New(rand.NewSource(time.Now().UnixNano()))

totalDuration := atomic.Int64{}
b.SetParallelism(1000)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
Expand All @@ -63,10 +65,13 @@ func BenchmarkParallelWrites(b *testing.B) {
}.Encode()
rsp := httptest.NewRecorder()

now := time.Now()
router.ServeHTTP(rsp, req)
totalDuration.Add(time.Since(now).Milliseconds())

require.Equal(b, http.StatusOK, rsp.Code)
}
})
b.StopTimer()
b.ReportMetric(float64(totalDuration.Load()/int64(b.N)), "ms/transaction")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/metric v0.37.0
go.opentelemetry.io/otel/trace v1.14.0
go.uber.org/atomic v1.10.0
go.uber.org/fx v1.19.2
golang.org/x/sync v0.1.0
gopkg.in/segmentio/analytics-go.v3 v3.1.0
Expand Down Expand Up @@ -146,7 +147,6 @@ require (
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.37.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.16.1 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
Expand Down

0 comments on commit 89e2fd9

Please sign in to comment.