findLongestWordLength

JavaScript performance comparison

Test case created by 200success

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function findLongestWordLength_DreamVision2017(str) {
    let strSplit = str.split(" ");
    let wordLengthArray = [];
    for(let i = 0; i < strSplit.length; i++)
    {
      wordLengthArray.push(strSplit[i].length);
    }
    wordLengthArray.sort(function(a , b){return a - b});
    return wordLengthArray[wordLengthArray.length - 1];
  }
  
  function findLongestWordLength_200_success(str) {
    let maxLen = -1;
    for (var i = 0, j; (j = str.indexOf(" ", i)) != -1; i = j + 1) {
      maxLen = Math.max(maxLen, j - i);
    }
    return Math.max(maxLen, str.length - i);
  }

};
</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
DreamVision2017
6 == findLongestWordLength_DreamVision2017("The quick brown fox jumped over the lazy dog");
5 == findLongestWordLength_DreamVision2017("May the force be with you");
6 == findLongestWordLength_DreamVision2017("Google do a barrel roll");
8 == findLongestWordLength_DreamVision2017("What is the average airspeed velocity of an unladen swallow");
19 == findLongestWordLength_DreamVision2017("What if we try a super-long word such as otorhinolaryngology");
pending…
200_success
6 == findLongestWordLength_200_success("The quick brown fox jumped over the lazy dog");
5 == findLongestWordLength_200_success("May the force be with you");
6 == findLongestWordLength_200_success("Google do a barrel roll");
8 == findLongestWordLength_200_success("What is the average airspeed velocity of an unladen swallow");
19 == findLongestWordLength_200_success("What if we try a super-long word such as otorhinolaryngology");
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