tinycon.js ua

JavaScript performance comparison

Test case created by darren

Info

check to see how optimisations improve the speed of library

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
original
var ua = function(browser) {
    var agent = navigator.userAgent.toLowerCase();
    return agent.indexOf(browser) !== -1;
    };

var browser = {
  chrome: ua('chrome'),
  webkit: ua('chrome') || ua('safari'),
  safari: ua('safari') && !ua('chrome'),
  mozilla: ua('mozilla') && !ua('chrome') && !ua('safari')
};
pending…
agent stored in closure
var ua = (function(browser) {
  var agent = navigator.userAgent.toLowerCase();
  // New function has access to 'agent' via closure
  return function(browser) {
    return agent.indexOf(browser) !== -1;
  };
}());
var browser = {
  chrome: ua('chrome'),
  webkit: ua('chrome') || ua('safari'),
  safari: ua('safari') && !ua('chrome'),
  mozilla: ua('mozilla') && !ua('chrome') && !ua('safari')
};
pending…
as 2, but using call
var ua = (function(browser) {
  var agent = navigator.userAgent.toLowerCase();
  // New function has access to 'agent' via closure
  return function(browser) {
    return agent.indexOf(browser) !== -1;
  };
}());
var browser = {
  chrome: ua.call(null, 'chrome'),
  webkit: ua.call(null, 'chrome') || ua.call(null, 'safari'),
  safari: ua.call(null, 'safari') && !ua.call(null, 'chrome'),
  mozilla: ua.call(null, 'mozilla') && !ua.call(null, 'chrome') && !ua.call(null, 'safari')
};
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment