3f_and_jQ
JavaScript performance comparison
Preparation code
<p name="p">1</p>
<p class="p">2</p>
<p id="p">3</p>
<p name="p">4</p>
<p class="p">5</p>
<p name="p">6</p>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function f1(a,b){a=a.match(/^(\W)?(.*)/);return(b||document)["getElement"+(a[1]?a[1]=="#"?"ById":"sByClassName":"sByTagName")](a[2])}
function f2(i,f,s){f=i[0];s=i.substr(1);return document['getElement'+({'#':'ById','.':'sByClassName'}[f]||'sByTagName')]({'#':s,'.':s}[f]||i)}
function f3(s){return document['getElement'+({'#':'ById','.':'sByClassName',$:'sByName'}[c=s[0]]||'sByTagName')](s.slice(c<'@'))}
function f4(a){a=/([#.]?)(.*)/.exec(a||'*');a=document['getElement'+(a[1]>'-'?'sByClassName':a[1]?'ById':'sByTagName')](a[2]);return a[0]||a}
function f5(s){return document['getElement'+({'#':'ById','.':'sByClassName',$:'sByName'}[c=s[0]]||'sByTagName')](s.substr(c<'@'))}
function f6(s){return document['getElement'+({'#':'ById','.':'sByClassName',$:'sByName'}[s[0]]||'sByTagName')](s.substr(s[0]<'@'))}
</script>
Preparation code output
1
2
3
4
5
6
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
1 |
|
pending… |
2 |
|
pending… |
3 |
|
pending… |
4 |
|
pending… |
5 |
|
pending… |
6 |
|
pending… |
7 |
|
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:
- Revision 1: published by Evghenusi
- Revision 2: published by Evghenusi
- Revision 3: published by Evghenusi
0 comments