Pages
Categories
Archives
JsTweeterManiac
- first time was on conference using skype call(toll free number). Skype is really great! 2 weeks ago
- RT @creationix: Connect app on quad-core machine over a real network connection. 35231.05 Reqs/sec http://bit.ly/aCWnd5 #nodejs #connect 1 month ago
- some provelinks #V8 vs #php http://ow.ly/1Xbg4 vs #ruby http://ow.ly/1Xbhl vs #Perl http://ow.ly/1Xbii vs #python http://ow.ly/1Xbjk 1 month ago
- http://ow.ly/1X9Z8 about #nodejs: "It is much faster than Ruby, Python, or Perl." really??? 1 month ago
- dyuproject(openID+oAuth) http://bit.ly/cfLC1b + facebook-java-api http://bit.ly/CnjrW + native google login. 2 months ago
- Strange, but there are so many Java libs are not created yet. I need openID + oAuth(twitter) + Facebook connect. 2 months ago
- Who will come to chatroulet next to perverts? - Salesmans http://bit.ly/d6HWS1 Shit! 2 months ago
- backend development excites much more than frontend. Frontend is kind of a job. And job is boring:).... Just kidding. 2 months ago
- I luv Microsoft. So many differences in browsers makes my salary much bigger. IE9 will not work on XP. Means long live 2 IE7-8. Horray!!! 2 months ago
- The Big Bang Theory: Everybody want to be Sheldon, Nobody wanna be Leonard:) 2 months ago
-
RSS Links
-
Meta
Javascript performance summary
I have an idea that Javascript could allow us to improve perfomance of our web applications. Of cause JS is very slow but unlike server side code we can run it on side of our clients. Something like client side cloud-computing.
It is jut an idea… for now.
Thing i can do right now is to improve performance of my scripts as much as possible. A lot can be gained just by following some coding style rules.
Javascript performance. Array vs Object
Reading and writing perfomance is not differs too much for this two. So you can easily use Object for mapping purposes and Array for unordered stuff.
details:
I have coded a simple profiler to test some siple pieces of code. Here it is:
function Profile(){ } Profile.prototype.status = 0;//0 free, 1 busy Profile.prototype.tests = []; Profile.prototype.testIt = function(){ if (!this.status && this.tests.length > 0) { var atest = this.tests.shift(); var that = this; var l = setTimeout(function(){ that.process(atest[0], atest[1], atest[2]); that.testIt(); }, 500); this.status = 1; } } Profile.prototype.profile = function(func, name, before){ Profile.prototype.tests.push([func, name, before]); this.testIt(); } Profile.prototype.process = function(func, name, before){ var AVGtime = 0; for (var i = 0; i < 20; i++) { var scope = {}; before.call(scope); var dbefore = new Date(); func.call(scope); var dafter = new Date(); AVGtime += dafter.getTime() - dbefore.getTime(); } this.report(func, AVGtime / 20, name); this.status = 0; } Profile.prototype.report = function(func, avg, name){ var funcDiv = document.createElement("div"); var report = "<div class='function' style='font-size: small; border: 1px solid #999; margin: 10px 0 3px 10px; padding: 5px;'>" + func.toString() + "</div"; report += "<div class='avgTime' style='font-weight: bold;margin: 0 0 0 10px'>" + name + ": " + avg + "ms</div>"; funcDiv.innerHTML = report; document.body.appendChild(funcDiv); }Here are the rules and results of all perfomance tests i run.
Javascript performance. Array vs Object