$ node runner.js
baseline { median: 43.16093, mean: 43.08483823809524 }
nanocolors { median: 47.465964, mean: 47.202760285714284 }
picocolors { median: 44.478806, mean: 44.252607809523816 }
chalk { median: 46.725678, mean: 47.159447523809526 }
picocolors { median: 44.538646, mean: 46.444677000000006 }
nanocolors { median: 47.159858, mean: 47.785727 }
baseline { median: 40.406613, mean: 40.227075666666664 }
chalk { median: 48.239906, mean: 48.22988314285714 }
chalk { median: 46.789621, mean: 46.71492319047619 }
picocolors { median: 43.16284, mean: 43.29260742857143 }
nanocolors { median: 42.462206, mean: 42.86361261904762 }
baseline { median: 40.483498, mean: 40.502954952380954 }
$ node runner.js
baseline { median: 41.804987, mean: 41.85401666666666 }
nanocolors { median: 45.051437, mean: 45.10202047619049 }
picocolors { median: 42.653881, mean: 42.79689666666667 }
chalk { median: 49.352838, mean: 49.264932476190474 }
picocolors { median: 43.797655, mean: 44.003986761904756 }
nanocolors { median: 43.388026, mean: 43.307937 }
baseline { median: 39.452398, mean: 39.344745095238096 }
chalk { median: 46.804137, mean: 46.92536761904762 }
chalk { median: 47.6746, mean: 47.61350923809524 }
picocolors { median: 43.324013, mean: 43.02372380952381 }
nanocolors { median: 42.498683, mean: 43.141994857142855 }
baseline { median: 40.574111, mean: 41.608522047619054 }
Last active
October 13, 2021 17:49
-
-
Save alexeyten/667e6163777783ed02879a0e3e66dd5d to your computer and use it in GitHub Desktop.
picocolors benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// empty |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let c = require('chalk'); | |
c.red('hello c'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let c = require('nanocolors'); | |
c.red('hello n'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let c = require('../picocolors.js'); | |
c.red('hello n'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const { fork } = require('child_process'); | |
const hrtime = process.hrtime.bigint; | |
const pfork = (path) => new Promise((resolve) => { | |
const start = hrtime(); | |
fork(path).on('exit', () => resolve(Number(hrtime() - start)/1e6)); | |
}); | |
async function bench(path, N = 25) { | |
path = require.resolve(path); | |
let t = []; | |
for (let i = 0; i < N; i++) { | |
t.push(await pfork(path)); | |
} | |
t.sort((a, b) => a - b); | |
return { | |
median: t[(N/2)|0], | |
mean: t.slice(2, -2).reduce((a, v) => a + v) / (N - 4) | |
}; | |
} | |
let baseline = 0; | |
Promise.resolve() | |
.then(() => bench('./baseline')) | |
.then((t) => { console.log('baseline ', t) }) | |
.then(() => bench('./nanocolors')) | |
.then((t) => { console.log('nanocolors', t) }) | |
.then(() => bench('./picocolors')) | |
.then((t) => { console.log('picocolors', t) }) | |
.then(() => bench('./chalk')) | |
.then((t) => { console.log('chalk ', t) }) | |
.then(() => bench('./picocolors')) | |
.then((t) => { console.log('picocolors', t) }) | |
.then(() => bench('./nanocolors')) | |
.then((t) => { console.log('nanocolors', t) }) | |
.then(() => bench('./baseline')) | |
.then((t) => { console.log('baseline ', t) }) | |
.then(() => bench('./chalk')) | |
.then((t) => { console.log('chalk ', t) }) | |
.then(() => bench('./chalk')) | |
.then((t) => { console.log('chalk ', t) }) | |
.then(() => bench('./picocolors')) | |
.then((t) => { console.log('picocolors', t) }) | |
.then(() => bench('./nanocolors')) | |
.then((t) => { console.log('nanocolors', t) }) | |
.then(() => bench('./baseline')) | |
.then((t) => { console.log('baseline ', t) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment