simple jquery selector vs 140medley

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

  <ul id="list">
    <li class="first">
<div class="first">
var re = new RegExp("^(\W)?(.*)");
var $$ = function(
  a,                         // take a simple selector like "name", "#name", or ".name", and
  b                          // an optional context, and
  a = a.match(re); // split the selector into name and symbol.
  return(                    // return an element or list, from within the scope of
    b                        // the passed context
    || document              // or document,
    "getElement" + (         // obtained by the appropriate method calculated by
        ? a[1] == "#"
          ? "ById"           // the node by ID,
          : "sByClassName"   // the nodes by class name, or
        : "sByTagName"       // the nodes by tag name,
    a[2]                     // called with the name.

$id = function(id) {
  return document.getElementById(id);
$tag = function(tag) {
  return document.getElementsByTag(tag);
$class = function(name) {
  return document.getElementsByClassName(name);
$extra=  function(selector, context)
  var a = context || document, wrapper = {};
     case '#': wrapper.el = a.getElementById(selector.slice(1));
     case '.': wrapper.el = a.getElementsByClassName(selector.slice(1));
     default: wrapper.el = a.getElementsByTagName(selector);
  return wrapper;

<script src=""></script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
find by Id (medley)
var list = $$('#list')
find by Id(jquery)
var list = $('#list')
find by id (vanilla)
var list = document.getElementById('list')
find by id (wrapper)
var list = $id('list')
find by id ($extra)
var list = $extra('#list')
find elements ($extra)
var list = $extra('li')
find elements (jquery)
var list = $('li')
find elements (medley)
var list = $$('li')

Compare results of other browsers


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:

1 comment

Erick RIbeiro commented :

Please check my test:

Comment form temporarily disabled.

Add a comment