Created
August 14, 2018 18:36
-
-
Save TMG-MattNewman/7215ddc4143b25c81ce239ecc0916b07 to your computer and use it in GitHub Desktop.
This file contains 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
var removeParam = () => {}; | |
var addParam = () => {}; | |
var thing = { toggle: { checked: true } }; | |
var domNodesCount = 20; | |
var functionOne = () => { | |
let listTitle = ''; | |
for (let i=domNodesCount; i>0; i--) { | |
if( thing.toggle.checked ) { | |
addParam( listTitle ); | |
} else { | |
removeParam( listTitle ); | |
} | |
} | |
} | |
var functionTwo = () => { | |
let listTitle = ''; | |
let addOrRemoveParam = () => { | |
return addParam( listTitle ); | |
} | |
if( thing.toggle.checked ) { | |
addOrRemoveParam = function ( listTitle ) { | |
return removeParam( listTitle ); | |
} | |
} | |
for (let i=domNodesCount; i>0; i--) { | |
addOrRemoveParam( listTitle ); | |
} | |
} | |
var iterations = 1000000; | |
console.time('Function #1'); | |
for(var i = 0; i < iterations; i++ ){ | |
functionOne(); | |
}; | |
console.timeEnd('Function #1') | |
console.time('Function #2'); | |
for(var i = 0; i < iterations; i++ ){ | |
functionTwo(); | |
}; | |
console.timeEnd('Function #2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment