Is it possible to benchmark a user's system with javascript in the browser
As Html5 starts gaining ground, we are seeing more experiments with things like the video or canvas element.
When making an experiment with the canvas for example making a firework with particles, 1000 particles may work well on a modern machine but may go very slowly on a 3yr machine.
Is there anyway to benchmark a users system to dynamically change a canvas experiment (or anything) so as to optimise it to said specific user.
EDIT: This 开发者_开发百科might possibly be the best solution: http://benchmarkjs.com/
Measure the time it takes to render a few frames of whatever you're doing and adjust the level of detail accordingly. If you don't mind the details changing on the fly, you could use continuous measuring.
What you don't want to do is make your user sit through a five-minute benchmark before they can do anything with your thing.
FutureMark's Peacekeeper Benchmark pretty much does this already. I think it tests a few other things too, but it does heavy canvas benchmarking as well.
I suppose you could devise some sort of a benchmark which measures the framerate on the canvas for the user and then adjusts details based on that. This could be accomplished by setting a short interval and rendering things on the canvas, then using Date
objects on each iteration to time how long it took and calculating an average framerate based on that.
Should be pretty simple. Just keep a frame counter and elapsed time in whatever function updates your canvas and divide the former by the latter to get FPS. You can scale down the number of particles/samples/etc. dynamically based off of the FPS. So basically--yes, but it's totally custom.
EDIT: Whoops... read the question too fast. My answer doesn't really apply.
Depends on the level of accuracy you want.
If you don't want something super accurate, it may be possible with a bit of work.
The way I see it; one of your biggest problems will be taking into account the various JS engines in different browsers, and metering everyone according to that specific browser and engine's baseline.
For example, try running any SunSpider test on IE 5.5 then on Google Chrome on the same machine... amazing difference. You'll have to take that into account. http://www.webkit.org/perf/sunspider/sunspider.html
Ideally, you'd want to correlate scores between different browsers as well (ie. this test runs in x ms on machine A in IE 6, and in y ms on the same machine in IE 8, so I can correlate IE 6 scores to IE 8 scores by using the average factor different). It might be hard to get a large enough sample size of data to do an effective job.
精彩评论