regex vs slice
JavaScript performance comparison
Preparation code
<script>
var toTypeRegExp = function(obj) {
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1];
}
var regExp = /\s([a-z|A-Z]+)/;
var toTypeCachedRegExp = function(obj) {
return ({}).toString.call(obj).match(regExp)[1];
}
var toTypeSlice = function(obj) {
return ({}).toString.call(obj).slice(8, -1);
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
regex no cache |
|
pending… |
regex with cache |
|
pending… |
slice |
|
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 WebReflection
- Revision 3: published
- Revision 4: published
- Revision 5: published by nfeldman
- Revision 6: published by PhiLho
- Revision 7: published
- Revision 8: published
- Revision 10: published by mauk
- Revision 11: published
- Revision 14: published by mauk
- Revision 16: published by mauk
0 comments