Skip to content

Instantly share code, notes, and snippets.

@Infocatcher
Created May 9, 2013 14:35
Show Gist options
  • Save Infocatcher/5547831 to your computer and use it in GitHub Desktop.
Save Infocatcher/5547831 to your computer and use it in GitHub Desktop.
Speed test: Components.utils.import() vs check + Components.utils.import()
var c = 30e3;
var tmr = "performance" in window && "now" in performance
? performance
: Date;
var Cu = Components.utils;
var i = c + 1, t = tmr.now();
while(--i)
Cu.import("resource://gre/modules/Services.jsm");
var dt1 = tmr.now() - t;
var i = c + 1, t = tmr.now();
while(--i)
if(!("Services" in window))
Cu.import("resource://gre/modules/Services.jsm");
var dt2 = tmr.now() - t;
alert("import: " + dt1 + "\nimport with check: " + dt2 + ", speed up: " + dt1/dt2);
/*
Firefox 20.0.1:
import: 513.3255428895354
import with check: 71.60421052761376, speed up: 7.168929579798584
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment