regex vs slice (v4)

Revision 4 of this benchmark created on


Preparation HTML

<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);
  }
  
  var toTypeSplitSlice = function(obj) {
    return ({}).toString.call(obj).split(" ").slice(0,-1);
  }
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
regex no cache
toTypeRegExp([1,2,3]);
 
ready
regex with cache
toTypeCachedRegExp([1,2,3]);
ready
slice
toTypeSlice([1,2,3]);
ready
splitslice
toTypeSplitSlice([1,2,3]);
ready

Revisions

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