Array Performance

JavaScript performance comparison

Revision 201 of this test case created by

Preparation code

<script>
Benchmark.prototype.setup = function() {
	var getItems = function(key){
		var items = [];
		for(var i = 0; i<30; i++) {
			items.push({
				name: "" + i + key,
				value: i + key
			});
		}
		return items;
	};
    var o1 = {}, o2 = {}, arr = [];
    var items = [""];
    for(var year = 2002; year <= 2015; year++) {

    	var yearObj = o1[year + ""] =  {
    		items: getItems(year)
    	};


    	var yearObj2 = o2[year + ""] =  {
    		items: getItems(year)
    	};

    	yearObj.months = {};
    	yearObj2.months = {};
    	for(var month = 0; month < 12; month++) {
    		var monthObj = yearObj.months[month + ""] = {
    			items: getItems(month)
    		};

    		var monthObj2 = yearObj2.months[month] = {
    			items: getItems(month)
    		};

    		monthObj.days = {};
    		monthObj2.days = {};
    		for(var day = 0; day < 31; day++) {
    			var dayObj = monthObj.days[day + ""] = {
    				items: getItems(day)
    			};
    			var dayObj2 = monthObj2.days[day] = {
    				items: getItems(day)
    			};

    			dayObj.hours = {};
    			dayObj2.hours = {};
    			for(var hour = 0; hour < 24; hour++) {
    				var hourObj = dayObj.hours[hour + ""] = {
	    				items: getItems(hour)
	    			};

    				var hourObj2 = dayObj2.hours[hour] = {
	    				items: getItems(hour)
	    			};

	    			hourObj.minutes = {};
	    			hourObj2.minutes = {};
	    			for(var minute = 0; minute < 60; ) {
	    				hourObj.minutes[minute + ""] = {
	    					items: getItems(minute)
	    				}
	    				hourObj2.minutes[minute] = {
	    					items: getItems(minute)
	    				}
	    				minute += 15;
	    			}
    			}
    			
    		}
    	}
    	arr.push(yearObj2);
	}
};
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Object Lookup
var yearObj = o1["2012"];
pending…
Object by Array
var yearObj = o2["2012"];
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.

0 Comments