javascript - requestAnimationFrame() performance issue -
i experienced performance issues requestanimationframe().
consider following code. it's simple loop prints time since last frame every time time delta larger 20ms.
const glob_time_info = {delta_time: 0.0, last_frame: performance.now()}; var render = function (timestamp) { glob_time_info.delta_time = timestamp - glob_time_info.last_frame; glob_time_info.last_frame = timestamp; if(glob_time_info.delta_time > 20) console.log(glob_time_info.delta_time); requestanimationframe(render); }; render(performance.now()); as understood requestanimationframe snippet should never print anything, because tries run 60 times second (60hz monitor). therefore time delta should around 16-17ms.
but prints times around 33ms every few seconds. why?
i experienced on windows 10 chrome 54 , firefox 49. own i5-6600
update here output of nit's script windows , ubuntu. windows, doing? windows 10 (pc):
windows 8 (same netbook below):
ubuntu (same netbook above): 
it's easy test hypothesis issue related platform you're running on - measure performance.
shortly put, run requestanimationframe number of times similar how did , note down timestamp on each run. after visualize results.
var times = []; var measure = function() { times.push(new date().gettime()); if (times.length > 100) return draw(); requestanimationframe(measure); }; var draw = function() { var dataset = { x: [], y: [], type: 'bar' }; var layout = { xaxis: { title: 'measurement #' }, yaxis: { title: 'iteration duration (ms)' }, height: 250 }; var options = { displaymodebar: false }; times.reduce(function(previous, current, i) { dataset.x.push(i); dataset.y.push(current - previous); return current; }, times.shift()); plotly.newplot('target', [dataset], layout, options); } measure(); #target { margin-top: -50px; } <script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script> <div id="target"></div> you can run same simulation on different operating systems , different browsers see if can narrow down issue further.
Comments
Post a Comment