Skip to content

Commit

Permalink
Merge pull request #12 from szkiba/feature/benchmarking
Browse files Browse the repository at this point in the history
feat: measuring the time required for transformation
  • Loading branch information
szkiba committed Apr 12, 2024
2 parents bcd9838 + 3dd2c9b commit c2d7742
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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.
8 changes: 8 additions & 0 deletions loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package ts
import (
"os"
"path/filepath"
"time"

"github.com/sirupsen/logrus"
"github.com/szkiba/k6pack"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c2d7742

Please sign in to comment.