navigator.platform.toLowerCase() speed (v4)

Revision 4 of this benchmark created by Jaie Wilson on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  jQuery.os = {};
  var platform = navigator.platform.toLowerCase();
  var winRe = /win/;
  var macRe = /mac/;
  var linuxRe = /linux/;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
No caching, long booleans
jQuery.os.windows = (navigator.platform.toLowerCase().indexOf("win") != -1) ? true : false;
jQuery.os.mac = (navigator.platform.toLowerCase().indexOf("mac") != -1) ? true : false;
jQuery.os.linux = (navigator.platform.toLowerCase().indexOf("linux") != -1) ? true : false;
ready
No caching, short booleans
jQuery.os.windows = (navigator.platform.toLowerCase().indexOf("win") != -1);
jQuery.os.mac = (navigator.platform.toLowerCase().indexOf("mac") != -1);
jQuery.os.linux = (navigator.platform.toLowerCase().indexOf("linux") != -1);
ready
Caching, short booleans
jQuery.os.windows = (platform.indexOf("win") != -1);
jQuery.os.mac = (platform.indexOf("mac") != -1);
jQuery.os.linux = (platform.indexOf("linux") != -1);
ready
Caching, long booleans
jQuery.os.windows = (platform.indexOf("win") != -1) ? true : false;
jQuery.os.mac = (platform.indexOf("mac") != -1) ? true : false;
jQuery.os.linux = (platform.indexOf("linux") != -1) ? true : false;
ready
Caching, regex
jQuery.os.windows = /win/.test(platform);
jQuery.os.mac = /mac/.test(platform);
jQuery.os.linux = /linux/.test(platform);
ready
Cached platform and Regex
jQuery.os.windows = winRe.test(platform);
jQuery.os.mac = macRe.test(platform);
jQuery.os.linux = linuxRe.test(platform);
ready

Revisions

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