every vs for

JavaScript performance comparison

Test case created by ghjk-code

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const alphabet = [...'abcdefghijklmnopqrstuvwxyz'];
  const sentence = 'the 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogsthe 1 quick brown fox !umps over the 2 lazy dogs';

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
every
const normalisedSentence = sentence.toLowerCase();
return alphabet.every(letter => normalisedSentence.includes(letter));
pending…
for
const normalisedSentence = sentence.toLowerCase();

  for (let i = 0; i < alphabet.length; i++) {
    if (!normalisedSentence.includes(alphabet[i])) {
      return false;
    }
  }

  return true;
pending…
every-lower-in-loop
alphabet
  .every(
     letter =>
        sentence.includes(letter) || sentence.includes(letter.toUpperCase())
    )
pending…

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

Compare results of other browsers

0 Comments