From 35578f6422e6425147b4707b3b8b9e4e70cfd659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Fri, 12 Apr 2024 14:26:50 +0200 Subject: [PATCH 1/2] feat: measuring the time required for transformation --- README.md | 6 +++++- loader.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e414f1..7eba394 100644 --- a/README.md +++ b/README.md @@ -126,4 +126,8 @@ Before the test run, transpilation and bundling are done on the fly. ## Compatibility warning -xk6-ts is currently integrated into k6 by modifying the execution of the `k6 run` command. This is a temporary solution, the final integration will be done in a different way. This temporary integration assumes that the last argument of the `k6 run` command line is the name of the script file. That is, contrary to the way the original `k6 run` command line works, xk6-ts does not accept flags after the script file name. By the way, this assumption is not uncommon, many other commands only accept flags before positional arguments. (the original `k6 run` command also accepts flags after the positional argument). \ No newline at end of file +xk6-ts is currently integrated into k6 by modifying the execution of the `k6 run` command. This is a temporary solution, the final integration will be done in a different way. This temporary integration assumes that the last argument of the `k6 run` command line is the name of the script file. That is, contrary to the way the original `k6 run` command line works, xk6-ts does not accept flags after the script file name. By the way, this assumption is not uncommon, many other commands only accept flags before positional arguments. (the original `k6 run` command also accepts flags after the positional argument). + +## Benchmarking + +Setting the `XK6_TS_BENCHMARK` environment variable to true will log the time spent on TypeScript/JavaScript bundling. This time also includes downloading any remote modules. diff --git a/loader.go b/loader.go index 305c680..3a9f0a1 100644 --- a/loader.go +++ b/loader.go @@ -4,6 +4,7 @@ package ts import ( "os" "path/filepath" + "time" "github.com/sirupsen/logrus" "github.com/szkiba/k6pack" @@ -65,11 +66,18 @@ func redirectStdin() { logrus.WithError(err).Fatal() } + packStarted := time.Now() + jsScript, err := k6pack.Pack(string(source), opts) if err != nil { logrus.WithError(err).Fatal() } + if os.Getenv("XK6_TS_BENCHMARK") == "true" { + duration := time.Since(packStarted) + logrus.WithField("extension", "xk6-ts").WithField("duration", duration).Info("Bundling completed in ", duration) + } + os.Args[scriptIndex] = "-" reader, writer, err := os.Pipe() From 3dd2c9bf23eb81cfd02c890a37d56837230033cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20SZKIBA?= Date: Fri, 12 Apr 2024 14:29:27 +0200 Subject: [PATCH 2/2] docs: fix formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7eba394..1ee7795 100644 --- a/README.md +++ b/README.md @@ -130,4 +130,4 @@ xk6-ts is currently integrated into k6 by modifying the execution of the `k6 run ## Benchmarking -Setting the `XK6_TS_BENCHMARK` environment variable to true will log the time spent on TypeScript/JavaScript bundling. This time also includes downloading any remote modules. +Setting the `XK6_TS_BENCHMARK` environment variable to `true` will log the time spent on TypeScript/JavaScript bundling. This time also includes downloading any remote modules.