Javascript 测量iOS每帧可以绘制多少次

Javascript 测量iOS每帧可以绘制多少次,javascript,ios,performance,benchmarking,graphic,Javascript,Ios,Performance,Benchmarking,Graphic,我正在尝试测试iOS与HTML5/JavaScript相比能够在帧刷新之间绘制多少次 使用此JavaScript,我可以得到浏览器在33毫秒(30赫兹)的时间内可以绘制的次数: var ctx=document.getElementById('canvas').getContext('2d'); var img=document.getElementById('img'); var draw=功能(负载){ var角=0.01; ctx.clearRect(0,0400); ctx.save()

我正在尝试测试iOS与HTML5/JavaScript相比能够在帧刷新之间绘制多少次

使用此JavaScript,我可以得到浏览器在33毫秒(30赫兹)的时间内可以绘制的次数:

var ctx=document.getElementById('canvas').getContext('2d');
var img=document.getElementById('img');
var draw=功能(负载){
var角=0.01;
ctx.clearRect(0,0400);
ctx.save();
ctx.translate(200200);

对于(var i=0;i请尝试使用instruments工具。您可以通过core animation instrument测量每个socond的帧数。

但这不是我试图捕获的FPS。这是iOS在屏幕更新之间可以绘制的次数。
var ctx = document.getElementById('canvas').getContext('2d');
var img = document.getElementById('img');

var draw = function(load) {
    var angle = 0.01;
    ctx.clearRect(0,0,400,400);
    ctx.save();
    ctx.translate(200,200);
    for (var i=0; i<load; i++) {
        ctx.rotate(angle);
        ctx.drawImage(img, 0, 0);
    }
    ctx.restore();
};

var t, previousTime;
var drawLoad = 1;
var slowCount = 0;
var maxSlow = 10;

var requestAnimationFrame = window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame;

t = previousTime = Date.now();

var tick = function() {
    var maximumFrameTime = 1000/30; // 30 FPS
    t = Date.now();
    var elapsed = t - previousTime;
    previousTime = t;
    if (elapsed < maximumFrameTime || slowCount < maxSlow) {
        if (elapsed < maximumFrameTime) {
            drawLoad+=10;
        } else {
            slowCount++;
        }
        draw(drawLoad);
        requestAnimationFrame(tick);
    } else {
      // found maximum sustainable load at 30 FPS
      document.getElementById('res').innerHTML = ("could draw "+(drawLoad)+" in " + maximumFrameTime + " ms");
    }
};
requestAnimationFrame(tick);