Set vs TemporarySetLike

Benchmark created on


Setup

const array = "abcdefghijklmnopqrstuvwxyz".split("");

class TemporarySetLike {
  /**
   * @param {T[]} array
   */
  constructor(array) {
    this.#array = array;
  }

  /**
   * The delegated Array
   * @type {readonly T[]}
   */
  #array;

  /**
   * Get the length of the delegated Array.
   * @type {number}
   */
  get size() {
    return this.#array.length;
  }

  /**
   * Get an iterator of the Array's indices.
   * @returns {ArrayIterator<number>}
   */
  keys() {
    return this.#array.keys();
  }

  /**
   * An indication of whether an element with the specified value exists in the Array
   * @param {unknown} value
   * @returns {boolean}
   */
  has(value) {
    return this.#array.includes(value);
  }
}

Test runner

Ready to run.

Testing in
TestOps/sec
Set
new Set(array)
ready
TemporarySetLike
new TemporarySetLike(array)
ready

Revisions

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