Skip to content

Instantly share code, notes, and snippets.

@phated
Created January 5, 2012 00:11
Show Gist options
  • Select an option

  • Save phated/1562974 to your computer and use it in GitHub Desktop.

Select an option

Save phated/1562974 to your computer and use it in GitHub Desktop.
Profiling of converting 10k json elements to html elements
<html>
<head>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>-->
<script src="https://raw.github.com/madrobby/zepto/master/src/zepto.js"></script>
<!--<script src="http://download.dojotoolkit.org/release-1.7.1/dojo.js"></script>-->
<script>
$(document).ready(function(){
//dojo.ready(function(){
var generated = '{';
for(var x = 0; x < 10000; x++) {
if(x !== 9999) {
generated += '"' + x + '":{"element":"p","content":"another test"},'
} else {
generated += '"' + x + '":{"element":"p","content":"another test"}'
}
}
generated += '}';
var template = JSON.parse(generated);
var parentElement = '';
var fragment = document.createDocumentFragment();
function html(key, value) {
if (key !== '') {
var element = '';
if(typeof(value) == 'string') {
if(key == 'element') {
element = document.createElement(value);
if(parentElement == '') {
parentElement = element;
fragment.appendChild(parentElement);
} else {
parentElement.appendChild(element);
parentElement = element;
}
} else if(key == 'content') {
parentElement.innerHTML = value;
parentElement = '';
}
}
}
return value;
}
var jsonString = JSON.stringify(template, html);
console.log(jsonString);
document.body.appendChild(fragment);
});
</script>
</head>
<body>
</body>
</html>
@phated

phated commented Jan 5, 2012

Copy link
Copy Markdown
Author

Zepto came in at 1.05 - 1.19 seconds
Jquery was around 1.66 seconds
Dojo was the worst at 1.89 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment