2015-01-16 34 views

回答

1

要對2個備選方案進行性能測試,請在記錄開始&結束時間時運行每個備選方案。

BTW,我返工你的畫布描邊線沒有陰影的工作應速度高達:

var canvas=document.getElementById("canvas"); 
 
var ctx=canvas.getContext("2d"); 
 
var cw=canvas.width; 
 
var ch=canvas.height; 
 

 

 
var pts = [{x:22,y:59.45},{x:136,y:66},{x:170,y:99},{x:171,y:114},{x:183,y:125},{x:218,y:144},{x:218,y:165},{x:226,y:193},{x:254,y:195},{x:283,y:195},{x:292,y:202},{x:325,y:213},{x:341,y:134},{x:397,y:245},{x:417,y:548}]; 
 

 

 
ctx.lineCap='round'; 
 
ctx.lineJoin='round'; 
 
ctx.lineWidth=25; 
 
ctx.strokeStyle='red'; 
 
drawPolyline(pts); 
 
ctx.lineWidth=22; 
 
ctx.strokeStyle='pink'; 
 
drawPolyline(pts); 
 
ctx.lineWidth=2; 
 
ctx.strokeStyle='blue'; 
 
drawPolyline(pts); 
 

 
function drawPolyline(pts){ 
 
    ctx.beginPath(); 
 
    ctx.moveTo(pts[0].x,pts[0].y); 
 
    for(var i=1;i<pts.length;i++){ 
 
    ctx.lineTo(pts[i].x,pts[i].y); 
 
    } 
 
    ctx.stroke(); 
 
}
body{ background-color: ivory; padding:10px; } 
 
#canvas{border:1px solid red;}
<canvas id="canvas" width=600 height=600></canvas>

+1

這主要措施解析爲渲染是異步的。除非UA提供內部工具來執行此操作,否則無法準確衡量所要求的內容,也無法加載具有特權訪問的某種插件。如果有的話,這將是一個隱私漏洞。 –

+0

好點 - 我的不好。我會編輯建議簡單的經過時間測試。謝謝你的回覆:-) – markE