Compare while loop vs for loop
JavaScript performance comparison
Preparation code
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
// first create a big array o' stuff
var BigArrayOStuff = [];
for (var j = 0; j < 10; j++) {
var dude = Object.create(null);
dude.RequirementName = "this is a test";
dude.Comment = "this is a test";
dude.NumberOfPresentations = "this is a test";
dude.RequirementId = "this is a test";
dude.CreateDate = "this is a test";
dude.UpdateDate = "this is a test";
dude.ProductId = "this is a test";
dude.QueryCategoryId = "this is a test";
BigArrayOStuff.push(dude);
}
// Constructor for requirement
var Req = function(options) {
this.name = options.name;
this.details = options.details;
this.presentations = []
this.numOfPresentations = options.numOfPresentations; // doing double duty: whether to show a "plus" icon on tree, and whether we have already loaded presentations
this.id = options.id;
this.clientId = options.clientId;
this.createdDate = options.createdDate;
this.updatedDate = options.updatedDate;
this.productId = options.productId;
this.queryCategoryId = options.queryCategoryId;
this.displayPresentations = false
this.isAnalytic = this.queryCategoryId === 3; // whether to show the little chart icon
};
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
underscore test
|
|
pending… |
native code for loop
|
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit
to the URL.
- Revision 1: published
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published Mark
- Revision 6: published
- Revision 7: published tav
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published Alex Bell
- Revision 15: published Oleg Buylov
- Revision 16: published
- Revision 17: published asasdfasdf
- Revision 18: published
- Revision 19: published sk
- Revision 21: published
- Revision 22: published
- Revision 23: published
- Revision 24: published
- Revision 25: published Stefan Feldbinder
- Revision 26: published Stefan Feldbinder
- Revision 27: published Stefan Feldbinder
- Revision 28: published Luca Gesmundo
- Revision 29: published Luca Gesmundo
- Revision 30: published
0 Comments