Skip to content

Commit

Permalink
chore: clean benchmark useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent 3f8b04c commit 1ebd494
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 39 deletions.
23 changes: 4 additions & 19 deletions test/performance/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ import (
"github.com/stretchr/testify/require"
)

type Iterator interface {
Next() bool
}

type RunConfiguration struct {
Env string
Script string
Features FeatureConfiguration
Ledger ledger.Ledger
}

func (c RunConfiguration) String() string {
return fmt.Sprintf("%s/%s/%s/%s/%s", c.Env, c.Script, c.Features, c.Ledger.Bucket, c.Ledger.Name)
}

type Benchmark struct {
EnvFactories map[string]EnvFactory
Scripts map[string]func(int) (string, map[string]string)
Expand Down Expand Up @@ -61,7 +46,7 @@ func (benchmark *Benchmark) Run(ctx context.Context) error {
}

cpt := atomic.Int64{}
report := newReport()
report := newReport(ledgerConfiguration.Features)

env := envFactory.Create(ctx, b, l)
b.Logf("ledger: %s/%s", l.Bucket, l.Name)
Expand All @@ -70,14 +55,14 @@ func (benchmark *Benchmark) Run(ctx context.Context) error {
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
id := int(cpt.Add(1))
iteration := int(cpt.Add(1))

script, vars := benchmark.Scripts[scriptName](id)
script, vars := benchmark.Scripts[scriptName](iteration)
now := time.Now()
_, err := env.Executor().ExecuteScript(ctx, script, vars)
require.NoError(b, err)

report.registerTransactionLatency(id, time.Since(now), err)
report.registerTransactionLatency(time.Since(now))
}
})
b.StopTimer()
Expand Down
27 changes: 7 additions & 20 deletions test/performance/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ import (
type Report struct {
mu sync.Mutex

features map[string]string

startOfBench time.Time
endOfBench time.Time

transactionsCount int

longestTransactionID int
longestTransactionDuration time.Duration

totalDuration atomic.Int64

errors map[int]error
transactionsCount int
}

func (r *Report) TPS() float64 {
Expand All @@ -33,26 +29,17 @@ func (r *Report) AverageDuration() time.Duration {
return time.Duration(r.totalDuration.Load()) * time.Millisecond / time.Duration(r.transactionsCount)
}

func (r *Report) LongestTransaction() (int, time.Duration) {
return r.longestTransactionID, r.longestTransactionDuration
}

func (r *Report) registerTransactionLatency(id int, latency time.Duration, err error) {
func (r *Report) registerTransactionLatency(latency time.Duration) {
r.mu.Lock()
defer r.mu.Unlock()

r.transactionsCount = r.transactionsCount + 1
if r.longestTransactionDuration < latency {
r.longestTransactionDuration = latency
r.longestTransactionID = id
}
r.transactionsCount++
r.totalDuration.Add(latency.Milliseconds())
r.errors[id] = err
}

func newReport() *Report {
func newReport(features map[string]string) *Report {
return &Report{
startOfBench: time.Now(),
errors: map[int]error{},
features: features,
}
}

0 comments on commit 1ebd494

Please sign in to comment.