Parse String for phrases

JavaScript performance comparison

Test case created by Stephon

Preparation code

<script>
var str = 'This "is some" sample "text"';
</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
match & replace
var str = 'This "is some" sample "text"';
var regex = /"(.*?)"/g;
var ret = str.match(regex);
for (var i = 0; i< ret.length; i++){
  var str = str.replace(ret[i], '');
}
pending…
quoteCount
var quoteCount = 0;
var nonQuote = '';
var quote = [];
var recording = '';
for (var i = 0; i < str.length; i++){
  if (str[i] == "\"")
  {
    quoteCount++;
  }
  if (quoteCount == 1)
  {
    recording += str[i];
  }
  else if (quoteCount == 2)
  {
    recording += str[i];
    quote.push(recording);
    recording = '';
    quoteCount = 0;
  }
  else
  {
    nonQuote += str[i];
  }
  if (i == str.length - 1 && quoteCount == 1)
  {
    nonQuote += recording;
  }
}
pending…

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

0 Comments