lijia3
JavaScript performance comparison
Preparation code
<canvas id="board" width="700" height="100">
<script>
Benchmark.prototype.setup = function() {
var value=[110,120,130,140,150,140,100,80,70,50];
var index=0;
window.calFunc= {
x: 0,
y: 0,
id: 0,
timer: 0,
currentXL: 30,
currentXR: 700,
initialX: 30,
initialY: 100,
lineWidth: 670,
guardian: false,
bcState: true,
drawBaseLine: function () {
var ctx = board.getContext("2d");
ctx.lineWidth = 4;
ctx.strokeStyle = "#4D90FE";
ctx.beginPath();
ctx.moveTo(calFunc.initialX, calFunc.initialY);
ctx.lineTo(calFunc.initialX + calFunc.lineWidth, calFunc.initialY);
ctx.stroke();
},
xdxd:function(x){
var asd=calFunc;
var y=asd.y;
var currentXL=asd.currentXL;
var difference = Math.floor(x - asd.x);
var ctx = asd.ctx;
ctx.clearRect(currentXL,y,670,1);
currentXL-=difference;
ctx.beginPath();
ctx.moveTo(currentXL,y);
ctx.lineTo(currentXL+670,y);
ctx.stroke();
},
ctx:board.getContext("2d"),
move2: function (x) {
var difference = Math.floor(x - calFunc.x);
var ctx = calFunc.ctx;
if (difference < 0) {
if (calFunc.currentXL + difference > 0) {
ctx.strokeStyle = "#4D90FE";
ctx.beginPath();
ctx.moveTo(calFunc.currentXL, calFunc.initialY);
calFunc.currentXL += difference;
ctx.lineTo(calFunc.currentXL, calFunc.initialY);
ctx.stroke();
}
if ((calFunc.currentXL + difference < 0 && calFunc.currentXR - calFunc.currentXL > 500) ||
calFunc.currentXR - calFunc.currentXL > calFunc.lineWidth) {
ctx.strokeStyle = "white";
ctx.beginPath();
ctx.moveTo(calFunc.currentXR, calFunc.initialY);
calFunc.currentXR += difference;
ctx.lineTo(calFunc.currentXR, calFunc.initialY);
ctx.stroke();
}
}
else {
if (calFunc.currentXR + difference < 730) {
ctx.strokeStyle = "#4D90FE";
ctx.beginPath();
ctx.moveTo(calFunc.currentXR, calFunc.initialY);
calFunc.currentXR += difference;
ctx.lineTo(calFunc.currentXR, calFunc.initialY);
ctx.stroke();
}
if (calFunc.currentXL < 300 && calFunc.currentXL + calFunc.currentXR > calFunc.lineWidth) {
ctx.strokeStyle = "white";
ctx.beginPath();
ctx.moveTo(calFunc.currentXL, calFunc.initialY);
calFunc.currentXL += difference;
ctx.lineTo(calFunc.currentXL, calFunc.initialY);
ctx.stroke();
}
}
calFunc.x = x;
},
move1: function (x) {
var difference = Math.floor(x - calFunc.x);
var ctx = board.getContext("2d");
if (difference < 0) {
if (calFunc.currentXL + difference > 0) {
ctx.strokeStyle = "#4D90FE";
ctx.beginPath();
ctx.moveTo(calFunc.currentXL, calFunc.initialY);
calFunc.currentXL += difference;
ctx.lineTo(calFunc.currentXL, calFunc.initialY);
ctx.stroke();
}
if ((calFunc.currentXL + difference < 0 && calFunc.currentXR - calFunc.currentXL > 500) ||
calFunc.currentXR - calFunc.currentXL > calFunc.lineWidth) {
ctx.strokeStyle = "white";
ctx.beginPath();
ctx.moveTo(calFunc.currentXR, calFunc.initialY);
calFunc.currentXR += difference;
ctx.lineTo(calFunc.currentXR, calFunc.initialY);
ctx.stroke();
}
}
else {
if (calFunc.currentXR + difference < 730) {
ctx.strokeStyle = "#4D90FE";
ctx.beginPath();
ctx.moveTo(calFunc.currentXR, calFunc.initialY);
calFunc.currentXR += difference;
ctx.lineTo(calFunc.currentXR, calFunc.initialY);
ctx.stroke();
}
if (calFunc.currentXL < 300 && calFunc.currentXL + calFunc.currentXR > calFunc.lineWidth) {
ctx.strokeStyle = "white";
ctx.beginPath();
ctx.moveTo(calFunc.currentXL, calFunc.initialY);
calFunc.currentXL += difference;
ctx.lineTo(calFunc.currentXL, calFunc.initialY);
ctx.stroke();
}
}
calFunc.x = x;
},
listener: function (e) {
if (calFunc.id != e.pointerId) return;
calFunc.move(e.pageX);
},
determine: function (e) {
if (calFunc.guardian) return;
calFunc.id = e.pointerId;
calFunc.x = e.pageX;
if (calFunc.x > 400) {
document.addEventListener("MSPointerMove", calFunc.listener, false);
document.addEventListener("MSPointerUp", calFunc.stop, false);
}
else {
calFunc.updateCursor();
calFunc.y = e.offsetY;
}
calFunc.guardian = true;
},
returnFromLeft: function () {
calFunc.move(calFunc.x + 10);
if (calFunc.currentXL > 20) {
calFunc.move(calFunc.x + 30 - calFunc.currentXL);
calFunc.guardian = false;
}
else {
setTimeout(calFunc.returnFromLeft, 50);
}
},
returnFromRight: function () {
calFunc.move(calFunc.x - 10);
if (calFunc.currentXL < 40) {
calFunc.move(calFunc.x + 30 - calFunc.currentXL);
calFunc.guardian = false;
clearInterval(calFunc.timer);
}
else {
setTimeout(calFunc.returnFromRight, 50);
}
},
stop: function (e) {
if (calFunc.id != e.pointerId) return;
document.removeEventListener("MSPointerMove", calFunc.listener, false);
document.removeEventListener("MSPointerUP", calFunc.stop, false);
if (calFunc.currentXL == 30) {
calFunc.guardian = false;
return;
}
if (calFunc.currentXL < 30) {
calFunc.returnFromLeft();
}
else {
calFunc.returnFromRight();
}
},
backSpace: function () {
var ctx = func1.getContext("2d");
ctx.lineWidth = 4;
ctx.lineCap = "round";
ctx.strokeStyle = "#5E5E5E";
ctx.beginPath();
ctx.moveTo(17, 35);
ctx.lineTo(2, 49);
ctx.moveTo(2, 50);
ctx.lineTo(42, 50);
ctx.moveTo(2, 51);
ctx.lineTo(17, 65);
ctx.stroke();
},
cross: function () {
var ctx = func2.getContext("2d");
ctx.lineWidth = 4;
ctx.strokeStyle = "#5E5E5E";
ctx.beginPath();
ctx.moveTo(0, 30);
ctx.lineTo(42, 70);
ctx.moveTo(42, 30);
ctx.lineTo(0, 70);
ctx.stroke();
},
reveal: function () {
if (calFunc.bcState) {
WinJS.UI.Animation.fadeIn(func1);
WinJS.UI.Animation.fadeIn(func2);
calFunc.timer = setTimeout(calFunc.hide, 2000);
calFunc.bcState = false;
}
else {
clearTimeout(calFunc.timer);
calFunc.timer = setTimeout(calFunc.hide, 2000);
}
},
hide: function () {
WinJS.UI.Animation.fadeOut(func1);
WinJS.UI.Animation.fadeOut(func2);
calFunc.bcState = true;
},
updateCursor: function () {
},
initialization: function () {
calFunc.drawBaseLine();
calFunc.cross();
calFunc.backSpace();
board.addEventListener("MSPointerDown", calFunc.determine, false);
}
}
calFunc.x=100;
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
1 |
|
pending… |
2 |
|
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. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published
- Revision 22: published
- Revision 23: published
- Revision 24: published
- Revision 25: published
- Revision 26: published
- Revision 27: published
- Revision 28: published
- Revision 29: published
- Revision 30: published
- Revision 31: published
- Revision 32: published
- Revision 33: published
- Revision 34: published
- Revision 35: published
- Revision 36: published
- Revision 37: published
- Revision 38: published
- Revision 39: published
- Revision 40: published
- Revision 41: published
- Revision 42: published
- Revision 43: published
- Revision 44: published
- Revision 45: published
- Revision 46: published
- Revision 47: published
0 comments