Test name | Executions per second |
---|---|
Vanilla JS | 1102079.8 Ops/sec |
Jquery | 224086.7 Ops/sec |
getbyid | 1253308.5 Ops/sec |
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div id="nhngodo">Hi! NHNgodo!</div>
<script>
window._getbyid = {};
function getbyid(elId){
if(!window._getbyid[elId]){
window._getbyid[elId] = document.getElementById(elId);
}
return window._getbyid[elId];
}
</script>
var el = document.getElementById("nhngodo");
el.innerText = "Hi! NHNgodo!";
$("#nhngodo").text("Hi! NHNgodo!");
getbyid("nhngodo").innerText = "Hi! NHNgodo!";