Skip to content

Commit

Permalink
feat(benchmarks): add -script flag to allow passing user custom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 23, 2024
1 parent 07b8b7b commit 1426329
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/performance/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (benchmark *Benchmark) Run(ctx context.Context) map[string][]Result {

b.SetParallelism(int(parallelismFlag))
b.ResetTimer()

b.RunParallel(func(pb *testing.PB) {

transactionProvider, err := benchmark.Scenarios[scenario].Create()
Expand All @@ -121,6 +122,7 @@ func (benchmark *Benchmark) Run(ctx context.Context) map[string][]Result {
iteration := int(cpt.Add(1))

script, vars := transactionProvider.Get(iteration)

now := time.Now()

_, err := benchmark.createTransaction(ctx, env.Client(), l, script, vars)
Expand Down
29 changes: 29 additions & 0 deletions test/performance/example_scripts/example1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const script = `vars {
account $order
account $seller
}
send [USD/2 100] (
source = @world
destination = $order
)
send [USD/2 1] (
source = $order
destination = @fees
)
send [USD/2 99] (
source = $order
destination = $seller
)`

function next(iteration) {
return {
script,
variables: {
order: `orders:${uuid()}`,
seller: `sellers:${iteration % 5}`
}
}
}



9 changes: 8 additions & 1 deletion test/performance/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
var (
authClientIDFlag string
authClientSecretFlag string
scriptFlag string

// targeting a stack
stackURLFlag string
Expand All @@ -46,6 +47,7 @@ func init() {
flag.StringVar(&authIssuerURLFlag, "auth.url", "", "Auth url (ignored if --stack.url is specified)")
flag.StringVar(&reportFileFlag, "report.file", "", "Location to write report file")
flag.Int64Var(&parallelismFlag, "parallelism", 1, "Parallelism (default 1). Values is multiplied by GOMAXPROCS")
flag.StringVar(&scriptFlag, "script", "", "Script to run")
}

//go:embed scripts
Expand Down Expand Up @@ -90,7 +92,7 @@ func BenchmarkWrite(b *testing.B) {
}

// Load default scripts
if len(scripts) == 0 {
if scriptFlag == "" {
entries, err := scriptsDir.ReadDir("scripts")
require.NoError(b, err)

Expand All @@ -104,6 +106,11 @@ func BenchmarkWrite(b *testing.B) {

scripts[strings.TrimSuffix(entry.Name(), ".js")] = NewJSTransactionProviderFactory(string(script))
}
} else {
file, err := os.ReadFile(scriptFlag)
require.NoError(b, err, "reading file "+scriptFlag)

scripts["provided"] = NewJSTransactionProviderFactory(string(file))
}

if envFactory == nil {
Expand Down

0 comments on commit 1426329

Please sign in to comment.