var li = document.createElement('li');
var ul = document.getElementById('results');
var div = document.getElementById('done');
var fib = function (cb) {
var stock = 0,
prev = 0,
curr = 1;
//Memorize starting time
var start = new Date().getTime();
//We calculate 10000 fibonnacci sequences
setTimeout(function () {
for (var i = 0; i < 10000; i++) {
//we clone the first li
var li_temp = li.cloneNode();
//fib stuff
stock = curr;
curr = curr + prev;
prev = stock;
//prepare the visual with fib num + time
li_temp.innerHTML = curr + '<br> time: <strong>' + (new Date().getTime() - start) + '</strong>';
//we append the new li to the list.
ul.appendChild(li_temp);
}
cb(start);
}, 0);
}
//we are done and we check how long everything took
var callback = function (start) {
div.innerHTML = 'We are done: ' + (new Date().getTime() - start);
}
fib(callback);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.