filter vs set - Remove Duplicates from an Array

Benchmark created on


Description

Remove Duplicate Items from an Array

Setup

var arr = new Array(1000000).fill().map(() => Math.round(Math.random() * 10 ** 3) / 10 ** 3);

Test runner

Ready to run.

Testing in
TestOps/sec
filter
var result = arr.filter((item, index) => arr.indexOf(item) === index);

ready
set
var result = [...new Set(arr)];
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.