Array.from(Set) vs Set#values().toArray()

Benchmark created on


Preparation HTML

<script type="module">
const { faker } = await import('https://esm.sh/@faker-js/faker');
window.faker = faker;
</script>

Setup

// Generate a Set with random length and values
const arr = new Set(Array.from({ length: Math.floor(Math.random() * 100) }).map(() =>
  faker.helpers.arrayElement([
    () => faker.word.sample(),
    () => faker.number.int(),
    () => faker.number.float(),
    () => faker.number.bigInt(),
    () => faker.helpers.arrayElement([false, true]),
  ])(),
));

Test runner

Ready to run.

Testing in
TestOps/sec
Array.from
const results = Array.from(arr);
ready
Set#values().toArray()
const results = arr.values().toArray();
ready

Revisions

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