speedracer
:racing_car::boom: ............ :red_car::taxi::blue_car::police_car::fire_engine::minibus::truck::bus::articulated_lorry::tractor:
Collect performance metrics for your library/application.
Speed Racer is a performance runner, like a test runner, but for performance 🏎. It runs scripts (races) in Chrome (headlessly if possible) and produces detailed traces and reports on scripting, rendering and painting.
See what's new in :package:
0.2.0
or what's being cooked for :package:
0.3.0
Installation
npm install -g speedracer
Speed Racer needs Google Chrome to run your files. It will run it headlessly if it finds a proper intallation of Canary (Mac OS X only for now).
Usage
Speed Racer comes with two commands right now:
run
: collect performance metrics and save them.display
: display a summary of generated reports.
Create races
A race can be seen as a unit test. It contains a piece of code that will be profiled by Speed Racer. Under the hood, it uses Chrome DevTools protocol to drive Chrome and collect traces.
Races can import es6
/ commonjs
modules and use most of es6
features, depending on your version of Google Chrome: es6 support
Here is an example of a file containing a race:
You can define as many races as you want per file, Speed Racer will collect and run them sequentially.
You can also define asynchronous races like so:
Run races
Then you need to collect metrics!
For each race, Speed Racer will produce two artifacts:
- a trace: a raw dump of Google Chrome tracing events, it contains a lot of detailed metrics about your race.
- a report: a report created by Speed Racer from those events, it summarizes important metrics.
Those artifacts will be saved in the .speedracer
directory by default.
To run races, type speedracer run perf/*.js
or simply speedracer perf/*.js
. Note that it will run all .js
files in the perf
directory by default, so you can omit perf/*.js
if you are using this directory.
For more details, type speedracer run --help
.
You can browse examples here.
Display reports
Once the artifacts have been created, you can quickly display a summary report for each run. Type speedracer display
to see all the reports or speedracer display .speedracer/a-file-name/*
to see the reports of a specific file.
For more details, type speedracer display --help
.
Go further
Speed Racer is still a baby so it does not provide advanced analysis yet, just a basic summary. But it has several goals:
- regression testing: compare runs over time and report how it's faster/slower.
- benchmarking: compare several races to see which is the best.
- analysis: give precise insights of what is slow and why.
- auditing: give advices on how to improve performance.
If you want to use Speed Racer for one of this use cases, you can leverage it and analyze the traces and reports it produces. I would be glad to receive your feedback and ideas on the subject!
Traces
Traces are json
files with the .trace.gz
extension. They are basically huge arrays of events produced by Google Chrome. Those events give tons of informations about the overall performance of race. Here is the detail format.
Traces can be pretty big, so they are saved gziped
.
You can analyze them the way you want or load them in the Timeline/Performance tab of Chrome like so:
- Locate and decompress your trace:
# first you need to locate and decompress the trace $ cd .speedracer$ lstext-fixtures-multiple$ cd text-fixtures-multiple$ lsrender-60-frames.speedracerrender-60-frames.trace.gzsearch-10e4-first-primes-very-long.speedracersearch-10e4-first-primes-very-long.trace.gz$ gunzip render-60-frames.trace.gz
- Load it in Chrome Devtools or use DevTools Timeline Viewer and enjoy 🎉
Reports
Reports are json
files with the .speedracer
extension. They provide a performance summary for a given race.
Here is the format:
You can display, analyze or compare them depending on your needs.
:racing_car::boom: ............ :red_car::taxi::blue_car::police_car::fire_engine::minibus::truck::bus::articulated_lorry::tractor: