regex vs slice

JavaScript performance comparison

Revision 8 of this test case created by

Preparation code

<script>
  var toTypeRegExp = function(obj) {
      return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1];
      }
      
  var toTypeSlice = function(obj) {
      return ({}).toString.call(obj).slice(8, -1);
      }
      
  var toTypeSliceProto = function(obj) {
      return Object.prototype.toString.call(obj).slice(8, -1);
      }
      
  var oproto = Object.prototype.toString;
  var toTypeSliceCachedProto = function(obj) {
      return oproto.call(obj).slice(8, -1);
      }
</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 no cache
toTypeRegExp([1, 2, 3]);
pending…
slice (literal)
toTypeSlice([1, 2, 3]);
pending…
slice (proto)
toTypeSliceProto([1, 2, 3]);
pending…
slice (cached proto)
toTypeSliceCachedProto([1, 2, 3])
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