dojo.replace vs manual replace

Benchmark created by Ben on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/dojo/1/dojo/dojo.xd.js"></script>

<script>
  string="this is a {0}. This is another {1}";
  arr=['test1','test2'];
  
  manualReplace= function(messageString, parameterArray) {
        var newString = messageString;
        for(var i=0; i<parameterArray.length; i++) {
                var exp = '{' + i + '}';
                newString = newString.replace(exp,parameterArray[i]);
        }
        return newString;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
dojo.replace
var a=dojo.replace(string,arr);
ready
manual replace
var b=manualReplace(string,arr);
ready

Revisions

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