teste de replace (2)

JavaScript performance comparison

Revision 5 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var texto = 'amarelo verde encarnado azul branco azul';

};
</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
regex
var r = new RegExp("azul", "g");
var resultado = texto.replace(r, "verde");
pending…
regex2
var r = /azul/g;
var resultado = texto.replace(r, "verde");
pending…
split/join
var resultado = texto.split('azul').join('verde');
pending…
indexOf
    var pos = texto.indexOf('azul');
    var ultpos = 0;
    var resultado = '';
    while (pos >= 0) {
        resultado += texto.substring(ultpos, pos) + 'verde';
        ultpos = pos + 4;
        pos = texto.indexOf('azul', pos + 4);
    }
    if (ultpos < texto.length) {
        resultado += texto.substring(ultpos, texto.length);
    }
pending…

Compare results of other browsers

Revisions

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

0 Comments