यह मजबूत विधि, requestAnimationFrame विधि का उपयोग कर रहा है।
function calcFPS(opts){
var requestFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame;
if (!requestFrame) return true; // Check if "true" is returned;
// pick default FPS, show error, etc...
function checker(){
if (index--) requestFrame(checker);
else {
// var result = 3*Math.round(count*1000/3/(performance.now()-start));
var result = count*1000/(performance.now()- start);
if (typeof opts.callback === "function") opts.callback(result);
console.log("Calculated: "+result+" frames per second");
}
}
if (!opts) opts = {};
var count = opts.count||60, index = count, start = performance.now();
checker();
}
उच्च count
का मूल्य, और अधिक सटीक एफपीएस के मूल्य, और अब एफपीएस परीक्षण का समय लगेगा।
अतिरिक्त तर्क का उपयोग 15/12 के लिए किया जा सकता है, यानी 24, 30, 48, 60 120 ... एफपीएस।
function calcFPS(a){function b(){if(f--)c(b);else{var e=3*Math.round(1E3*d/3/(performance.now()-g));"function"===typeof a.callback&&a.callback(e);console.log("Calculated: "+e+" frames per second")}}var c=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame;if(!c)return!0;a||(a={});var d=a.count||60,f=d,g=performance.now();b()}
इसलिए की तरह उपयोग किया::
यहाँ संकलित संस्करण (साथ गोलाई से 3 एफपीएस) है
calcFPS(); // Only logs to console (you can remove the console log,
// making this call redundant)
calcFPS({count: 30}); // Manually set count (the test should take 500ms
// on a 60FPS monitor
calcFPS({callback: useFPS}); // Specify a callback so you can use the
// FPS number value
var FPS = 0, err = calcFPS({count: 120, callback: fps => FPS = fps});
if (err) FPS = 30;
सवाल यह है कि नहीं "कैसे" लेकिन "क्यों" । विशेष रूप से उत्तरार्द्ध के लिए। – ThiefMaster
शायद जावास्क्रिप्ट के साथ मूल क्लाइंट का उपयोग करके? – Shaz
मैं ऐसी परिस्थिति की कल्पना नहीं कर सकता जहां आप फ्रेम रीफ्रेश पर कॉलबैक निष्पादित करना चाहते हैं ... आप 60 बार एक सेकेंड कॉल करना चाहते हैं? आपको एक्स फ्रेम तक गिनने के लिए कुछ कॉल करना होगा (मान लीजिए कि आप यह जानकारी पहले स्थान पर प्राप्त कर सकते हैं। – colinross