this doesn't modify the original array and you aren't saving the result...
You should also use different files to run each algo just so it's isolated and the second one isn't benefiting from JIT optimization from the first.
Another thing, you don't want to include the time to generate the array in your measurement since you're really interested in the deduping.
I did it with the modifications suggested and Set version is much faster than indexOf as the array gets larger, which isn't surprising.
Here's output for the 10_000 loop
~/perf
❯ node -v
v15.14.0
~/perf
❯ time node indexOf.js
Took 3.4395 milliseconds to generate:
node indexOf.js 1.14s user 0.89s system 110% cpu 1.849 total
~/perf
❯ time node indexOf.js
Took 3.4735 milliseconds to generate:
node indexOf.js 1.15s user 0.91s system 110% cpu 1.862 total
~/perf
❯ time node indexOf.js
Took 3.4432 milliseconds to generate:
node indexOf.js 1.15s user 0.92s system 111% cpu 1.857 total
~/perf
❯ time node set.js
Took 0.9747 milliseconds to generate:
node set.js 1.18s user 0.90s system 111% cpu 1.869 total
~/perf
❯ time node set.js
Took 0.8821 milliseconds to generate:
node set.js 1.20s user 0.91s system 111% cpu 1.890 total
~/perf
❯ time node set.js
Took 0.9954 milliseconds to generate:
node set.js 1.20s user 0.90s system 111% cpu 1.886 total
20
u/slowthedataleak May 14 '21
Does this perform better than filter()?