Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save UplandsDynamic/d141ed6627b9fc8688d701ff9efd4bd3 to your computer and use it in GitHub Desktop.
Save UplandsDynamic/d141ed6627b9fc8688d701ff9efd4bd3 to your computer and use it in GitHub Desktop.
Javascript performance tests: Remove elements from array
let o1 = performance.now();
let test = ['a', 'b', 'c']
let toRemove = test.indexOf('b');
if(toRemove !== -1){
test.splice(toRemove, 1)
console.log(test);
}
let o2 = performance.now();
console.log(o2 - o1);
let t1 = performance.now();
let test2 = ['a', 'b', 'c'];
console.log(test2.filter(v => v !== 'b'));
let t2 = performance.now();
console.log(t2 - t1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment