Skip to content

Instantly share code, notes, and snippets.

@TMG-MattNewman
Created August 14, 2018 18:36
Show Gist options
  • Save TMG-MattNewman/7215ddc4143b25c81ce239ecc0916b07 to your computer and use it in GitHub Desktop.
Save TMG-MattNewman/7215ddc4143b25c81ce239ecc0916b07 to your computer and use it in GitHub Desktop.
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