document.scripts vs getElementsByTagName

JavaScript performance comparison

Test case created by Josh Rhoades

Info

Test to compare native document.scripts to document.getElementsByTagName('scripts')

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
getElementsByTagName('script')
function getScriptsByTag() {
  var arrScripts = document.getElementsByTagName('script') || [],
    l = arrScripts.length,
    i = 0,
    theScript;
  for (; i < l; i++) {
    theScript = arrScripts[i];
    console.log('getScriptsByTag', theScript);
  }
}
pending…
document.scripts
function getScriptsByNative() {
  var arrScripts = document.scripts || [],
    l = arrScripts.length,
    i = 0,
    theScript;

  for (; i < l; i++) {
    theScript = arrScripts[i];
    console.log('getScriptsByNative', theScript);
  }
}
pending…

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

Compare results of other browsers

0 comments

Add a comment