regex vs slice (v20)

Revision 20 of this benchmark created on


Preparation HTML

<script>
var toType = function(obj){
return typeof obj;
}
  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

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
typeof
toType([1, 2, 3]);
ready

Revisions

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