regex vs slice (v8)

Revision 8 of this benchmark created on


Preparation HTML

<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

Ready to run.

Testing in
TestOps/sec
regex no cache
toTypeRegExp([1, 2, 3]);
ready
slice (literal)
toTypeSlice([1, 2, 3]);
ready
slice (proto)
toTypeSliceProto([1, 2, 3]);
ready
slice (cached proto)
toTypeSliceCachedProto([1, 2, 3])
ready

Revisions

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