From 89fa056643ef9468f193e4f5446abdb786ded956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Fri, 23 Jun 2023 16:50:44 +0200 Subject: [PATCH] Add benchmarks for run command with and without events See the results here: https://gist.github.com/imiric/b2094c79f45cbdbdcb067671434fde4a --- cmd/tests/cmd_run_test.go | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index 2bc44725ca78..0df7021af5dd 100644 --- a/cmd/tests/cmd_run_test.go +++ b/cmd/tests/cmd_run_test.go @@ -2165,3 +2165,66 @@ func TestEventSystemError(t *testing.T) { }) } } + +func BenchmarkRun(b *testing.B) { + b.StopTimer() + + for i := 0; i < b.N; i++ { + ts := NewGlobalTestState(b) + + ts.CmdArgs = []string{"k6", "--quiet", "run", "-"} + ts.Stdin = bytes.NewBuffer([]byte(` + export let options = { + vus: 10, + iterations: 100, + } + + export default function () {} + `)) + ts.ExpectedExitCode = 0 + + b.StartTimer() + cmd.ExecuteWithGlobalState(ts.GlobalState) + b.StopTimer() + } +} + +func BenchmarkRunEvents(b *testing.B) { + b.StopTimer() + + for i := 0; i < b.N; i++ { + ts := NewGlobalTestState(b) + + moduleName := fmt.Sprintf("k6/x/testevents-%d", atomic.AddUint64(&uniqueModuleNumber, 1)) + mod := events.New(event.GlobalEvents, event.VUEvents) + modules.Register(moduleName, mod) + + ts.CmdArgs = []string{"k6", "--quiet", "run", "-"} + ts.Stdin = bytes.NewBuffer([]byte(fmt.Sprintf(` + import events from '%s'; + export let options = { + vus: 10, + iterations: 100, + } + + export default function () {} + `, moduleName))) + ts.ExpectedExitCode = 0 + + b.StartTimer() + cmd.ExecuteWithGlobalState(ts.GlobalState) + b.StopTimer() + + doneCh := make(chan struct{}) + go func() { + mod.WG.Wait() + close(doneCh) + }() + + select { + case <-doneCh: + case <-time.After(time.Second): + b.Fatal("timed out") + } + } +}