.replace() vs. .split().join() vs .replaceAll()
JavaScript performance comparison
Info
A solution for replacement of strings.
Preparation code
<script>
Benchmark.prototype.setup = function() {
var mystring = 'okay.this.is.a.string';
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
.replace(/\./g,' ') |
|
pending… |
.replace(new RegExp(".","gm")," ") |
|
pending… |
.split('.').join(' ') |
|
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 by Roberto Frega
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published by rmaksim
- Revision 6: published by dongy
- Revision 9: published
- Revision 10: published by Jens Duttke
- Revision 11: published
- Revision 12: published
- Revision 14: published
- Revision 15: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published
- Revision 23: published by Sanderd17
- Revision 24: published
- Revision 25: published by joequincy
- Revision 26: published
- Revision 27: published
- Revision 28: published
- Revision 29: published
- Revision 30: published
- Revision 31: published by Tamil Vendhan
- Revision 32: published
- Revision 33: published
- Revision 34: published
0 comments