0

与 HTML5/JavaScript 相比,我正在尝试对 iOS 本身可以在帧刷新之间绘制多少次进行基准测试。

使用这个 JavaScript,我得到了一个数字,说明浏览器在 33 毫秒(30 赫兹)期间可以绘制多少次:

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);

有关带有 HTML 标记的完整代码,请参见http://jsfiddle.net/tbhZs/117/

我在objective-c中摆弄,没有找到一种公平的方法来获得一个可比较的数字。有没有办法在 iOS 中本地生成可比较的基准?

4

1 回答 1

0

Try instruments tool. you can measure the frames per socond via the core animation instrument.

于 2013-04-22T17:52:46.960 回答