<!DOCTYPE html>
<html debug="true">
<head>
<script src="../lib/Firebug/firebug.js"></script>
<script src="../OpenLayers.js"></script>
<script>
function avg(t) {
var s = 0;
for(var i=0, l=t.length; i<l; i++) {
s += t[i];
}
return s / l;
}
var Pixel1 = OpenLayers.Class({
initialize: function(x, y) {
this.x = x;
this.y = y;
}
});
var Pixel2 = function(x, y) {
this.x = x; this.y = y;
};
var NUM = 20;
var i, j, l, start, stop, p, times = new Array(NUM);
// case 1
for(i=0; i<NUM; i++) {
start = new Date;
for(j=0,l=100000; j<l; j++) {
p = new Pixel1(23.4, 42.4);
}
stop = new Date;
times[i] = stop.getTime()-start.getTime();
}
console.log("OpenLayers.Class", avg(times));
// case 2
for(i=0; i<NUM; i++) {
start = new Date;
for(j=0,l=100000; j<l; j++) {
p = new Pixel2(23.4, 42.4);
}
stop = new Date;
times[i] = stop.getTime()-start.getTime();
}
console.log("Pure JavaScript", avg(times));
// case 3
for(i=0; i<NUM; i++) {
start = new Date;
for(j=0,l=100000; j<l; j++) {
p = {x: 23.4, y: 42.4};
}
stop = new Date;
times[i] = stop.getTime()-start.getTime();
}
console.log("Object Litteral", avg(times));
</script>
</head>
<body>
</body>
</html>