pixelmatch
pixelmatch copied to clipboard
spread parameter is slow
The small patch draws pixels up to x27 times faster.
The current code draws a pixel with spread parameters drawPixel(output, pos, ...color).
The magic ... looks cool but runs slower compared to traditional coding styles still.
| code x 100,000,000 times | Chrome 96 | Safari 15 | Firefox 95 | result |
|---|---|---|---|---|
drawPixel(output, pos, ...color) |
1,333 ms | 4,289 ms | 5,230 ms | slow 👎 |
drawPixel(output, pos, color[0], color[1], color[2]) |
246 ms | 1,552 ms | 492 ms | fast 👍 |
drawColorFn(output, color)(pos) |
144 ms | 1,154 ms | 190 ms | faster 👍 👍 |
The benchmark above was tested on MacBook M1 Apple Silicon. Try it: https://gist.github.com/kawanet/4676a1804bb463ea558017b063d4c286