Created
August 9, 2019 08:48
-
-
Save artalar/fd59d8ad22b25946b987f030798a278f to your computer and use it in GitHub Desktop.
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
| const { performance } = require('perf_hooks'); | |
| let counter = 0; | |
| let log = []; | |
| function logPure(log, value) { | |
| log.push(value); | |
| } | |
| function logDirty() { | |
| log.push(counter); | |
| } | |
| // %NeverOptimizeFunction(logPure); | |
| // %NeverOptimizeFunction(logDirty); | |
| { | |
| log = []; | |
| let i = 10000; | |
| const tStart = performance.now(); | |
| while (i--) logPure(log, counter); | |
| console.log('pure: ', performance.now() - tStart); | |
| } | |
| { | |
| log = []; | |
| let i = 10000; | |
| const tStart = performance.now(); | |
| while (i--) logDirty(counter); | |
| console.log('dirty: ', performance.now() - tStart); | |
| } | |
| { | |
| log = []; | |
| let i = 10000; | |
| const tStart = performance.now(); | |
| while (i--) log.push(counter); | |
| console.log('inline: ', performance.now() - tStart); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment