
var template = {"url":"http://jsbin.com/uvoye","html" : "<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\">\n<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n<script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.3.2\/jquery.min.js\"><\/script>\n<script type=\"text\/javascript\">\nvar arr = null;\n\nfunction profileFunction(func, description, timesToRun) {\n   var elapsedTime = 0;\n   for (var i = 0; i < timesToRun; ++i) {\n      elapsedTime += profile(func);\n   }\n   var averageTime = elapsedTime \/ timesToRun;\n   console.log(\"Average Time for '%s': %i ms (%i Iterations)\", description, averageTime, timesToRun);\n}\n\nfunction profile(func) {\n   var start = new Date().getTime();\n   func();\n   var elapsedTime = (new Date().getTime()) - start;\t\n   return elapsedTime;\n}\n\nfunction whileLoopCached() {\n   var i = 0, arrLength = arr.length;\n   while (i < arrLength) { arr[i]; i++; }\n}\n\nfunction reverseWhileLoop() {\n   var i = arr.length; \n   while (i--) { arr[i]; }\n}\n\nfunction oldAndBusted() {\n   for (var i = 0; i < arr.length; ++i) { arr[i]; }\n}\n\nfunction oldAndBustedCached() {\n   var arrLength = arr.length;\n   for (var i = 0; i < arrLength; ++i) { arr[i]; }\n}\n\nfunction coolGuyLoop() {\n   for (var i = -1, len = arr.length; ++i < len; ) { arr[i]; } \n}\n\nfunction coolGuyLoopCached() {\n   var arrLength = arr.length;\n   for (var i = -1, len = arrLength; ++i < len; ) { arr[i]; } \n}\n\n<\/script>\n<title>Sandbox<\/title>\n<meta http-equiv=\"Content-type\" content=\"text\/html; charset=utf-8\" \/>\n<style type=\"text\/css\" media=\"screen\">\nbody { background-color: #000; font: 16px Helvetica, Arial; color: #fff; }\n<\/style>\n<\/head>\n<body>\n   <h3>JavaScript Loop Profiling<\/h3>\n   <p>Number of Iterations<\/p>\n   <input id='numberOfIterations' type='text' value='100' \/>\n   <p>Array Length<\/p>\n   <input id='arrayLength' type='text' value='1000000' \/>\n   <button>Profile<\/button>\n   <script type='text\/javascript'>\n   $('button').click(function() {\n      var numberOfIterations = parseInt($('#numberOfIterations').val());\n      var arrayLength = parseInt($('#arrayLength').val());\n      arr = new Array(arrayLength);\n\t  console.clear();\n      console.log('Array Length: ' + arr.length)\n      profileFunction(oldAndBusted, 'old and busted', numberOfIterations);\n      profileFunction(oldAndBustedCached, 'old and busted cached', numberOfIterations);\n      profileFunction(coolGuyLoop, 'the cool guy loop', numberOfIterations);\n      profileFunction(coolGuyLoopCached, 'the cool guy loop cached', numberOfIterations);   \n\t  profileFunction(whileLoopCached, 'while loop cached', numberOfIterations);\n\t  profileFunction(reverseWhileLoop, 'reverse while loop', numberOfIterations);\n   });\n   <\/script>\n<\/body>\n<\/html>","javascript":"if (document.getElementById('hello')) {\n  document.getElementById('hello').innerHTML = 'Hello World - this was inserted using JavaScript';\n}\n"}
