Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance optimizations (ca. Factor 75)
- Precomputed style function - Skip arguments to array + join if there's only one argument (the common case) - Merge multiple return statements to one To calculate the performance benefit: ```javascript var chalk = require('./index.js'); console.time('100000 iterations'); for (var i = 0; i < 100000; i++) { chalk.red('A string that is about 80 characters long (normal use I think?)'); } console.timeEnd('100000 iterations'); ``` Running this before this commit: ```shell for i in {1..5}; do node time.js; done 100000 iterations: 19485ms 100000 iterations: 18933ms 100000 iterations: 19365ms 100000 iterations: 19332ms 100000 iterations: 18660ms ``` After: ```shell 100000 iterations: 268ms 100000 iterations: 261ms 100000 iterations: 264ms 100000 iterations: 259ms 100000 iterations: 254ms ``` Performance gain, taking the middle result of both: ```shell 19332 / 261 = 74.~ ``` Closes chalk#16
- Loading branch information