String concat vs regex replace
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var view = {
name: "test",
value: 5
},
template = "Hello, my name is {name} and my value is {value}",
render = function fmt(s,a,r){r=/\{([^}]+)\}/g;return s.replace(r,function(_,m){return a[m]})};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
String join |
|
pending… |
Using a regex |
|
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. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published by Dave Kinsella
- Revision 4: published
- Revision 5: published
- Revision 6: published
- Revision 7: published by iampeterbanjo
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 14: published
0 comments