mobile simple detection (v2)

Revision 2 of this benchmark created by Dan L on


Description

Testing evaluation of all RegEx at once... New Test3 is faster on my browser...

Preparation HTML

<script>

var ios, android, blackBerry, windows, smartphone, tablet, all;

var mobileCheck = {
  ios: (function(){
    return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  }()),
  android: (function(){
    return navigator.userAgent.match(/Android/i);
  }()),
  blackBerry: (function(){
    return navigator.userAgent.match(/BB10|Tablet|Mobile/i);
  }()),
  windows: (function(){
    return navigator.userAgent.match(/IEMobile/i);
  }()),
  smartphone: (function(){
    return (window.innerWidth <= 384 && window.innerHeight <= 640);
  }()),
  tablet: (function(){
    return (navigator.userAgent.match(/Tablet|iPad|iPod/i) && window.innerWidth <= 1280 && window.innerHeight <= 800);
  }()),
  all: (function(){
    return navigator.userAgent.match(/Android|BlackBerry|Tablet|Mobile|iPhone|iPad|iPod|Opera Mini|IEMobile/i);
  }())
};

var mobileCheck_2 = {
  ios: (function(){
    return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  }),
  android: (function(){
    return navigator.userAgent.match(/Android/i);
  }),
  blackBerry: (function(){
    return navigator.userAgent.match(/BB10|Tablet|Mobile/i);
  }),
  windows: (function(){
    return navigator.userAgent.match(/IEMobile/i);
  }),
  smartphone: (function(){
    return (window.innerWidth <= 384 && window.innerHeight <= 640);
  }),
  tablet: (function(){
    return (navigator.userAgent.match(/Tablet|iPad|iPod/i) && window.innerWidth <= 1280 && window.innerHeight <= 800);
  }),
  all: (function(){
    return navigator.userAgent.match(/Android|BlackBerry|Tablet|Mobile|iPhone|iPad|iPod|Opera Mini|IEMobile/i);
  })
};

var mobileCheck_3 = function() {
return {
  ios: navigator.userAgent.match(/iPhone|iPad|iPod/i),
  android: navigator.userAgent.match(/Android/i),
  blackBerry: navigator.userAgent.match(/BB10|Tablet|Mobile/i),
  windows: navigator.userAgent.match(/IEMobile/i),
  smartphone: (window.innerWidth <= 384 && window.innerHeight <= 640),
  tablet: (navigator.userAgent.match(/Tablet|iPad|iPod/i) && window.innerWidth <= 1280 && window.innerHeight <= 800),
  all: navigator.userAgent.match(/Android|BlackBerry|Tablet|Mobile|iPhone|iPad|iPod|Opera Mini|IEMobile/i)
}
};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
mobileCheck
ios = mobileCheck.ios;
android = mobileCheck.android;
blackBerry = mobileCheck.blackBerry;
windows = mobileCheck.windows;
smartphone = mobileCheck.smartphone;
tablet = mobileCheck.tablet;
all = mobileCheck.all;
ready
mobileCheck_2
ios = mobileCheck_2.ios;
android = mobileCheck_2.android;
blackBerry = mobileCheck_2.blackBerry;
windows = mobileCheck_2.windows;
smartphone = mobileCheck_2.smartphone;
tablet = mobileCheck_2.tablet;
all = mobileCheck_2.all;
ready
mobileCheck_3
ios = mobileCheck_3.ios;
android = mobileCheck_3.android;
blackBerry = mobileCheck_3.blackBerry;
windows = mobileCheck_3.windows;
smartphone = mobileCheck_3.smartphone;
tablet = mobileCheck_3.tablet;
all = mobileCheck_3.all;
ready

Revisions

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