Testing unique values speed

Benchmark created on


Description

Because why not

Preparation HTML

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" />

Test runner

Ready to run.

Testing in
TestOps/sec
With Set
const fn = (existing, newVal) => {
  return [...new Set(arr)];	
}

fn([1, 2, 3], 1)
ready
With Return false
const fn = (existing, newVal) => {
	if (existing.includes(newVal)) {
		return existing
	}
	
  return [...new Set(arr)];	
}

fn([1, 2, 3], 1)
ready
With Lodash
const fn = (existing, newVal) => {

  return _.uniq([...existing, newVal])
}

fn([1, 2, 3], 1)
ready

Revisions

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