Load Testing Tool k6 --compatibility-mode=base Sample Code
This article introduces sample code for running the load testing tool k6 with the —compatibility-mode=base option.
--compatibility-mode=base
The most impactful option to improve k6 performance is to use —compatibility-mode=base to disable the internal Babel transpilation and run a k6 script written in ES5.1.
# compatibility-mode=base disables the Babel transpilation and the inclusion of corejs k6 run --compatibility-mode=base yourscript.es5.js
Background
Most k6 script examples and documentation are written in ES6+.
By default, k6 transpiles ES6+ code to ES5.1 using babel and loads corejs to enable commonly used APIs. This works very well for 99% of use cases, but it adds significant overheard with large tests.
When running a ES5.1 script instead of the original ES6+ script, k6 can use about 50-85% of memory and significantly reduce the CPU load and startup time.
We’ll use the npm scripts introduced in How to Transpile ES6 to ES5 with webpack + Babel.
MY_K6_TARGET_FILENAME=your_k6_es6_file.js
npm run to-es5 ./src/$MY_K6_TARGET_FILENAME
k6 run --compatibility-mode=base \
--out csv=./dist/output-$MY_K6_TARGET_FILENAME.csv \
./dist/$MY_K6_TARGET_FILENAME
That’s all from the Gemba on using the —compatibility-mode=base option to run load testing tool k6 at high speed.