Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 463
Sycren Avatar asked Jun 27 '11 22:06

Sycren


People also ask

What is benchmark JS used for?

Benchmark.js is a commonly used tool for measuring the execution time of JavaScript code, supporting high-resolution timers for measurement accuracy, and ensuring statistically significant results are returned. A number of web tools are based on Benchmark.js, allowing you to quickly create test suites that you can then run in browsers.

Is handwritten or handwritten JS benchmarking better?

As you can see, the handwritten version performs significantly better, and so JSBench.Me highlights that test case as being the fastest, and identifies how much slower each of the other test cases is.

What can you do with Benchmark?

Now that you know the basics of using Benchmark.js, you can start to make quantitative decisions about the performance of your code, and prove when you are making improvements. Go forth and make your code faster!


2 Answers

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.

like image 167
Matti Virkkunen Avatar answered Nov 04 '22 21:11

Matti Virkkunen


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.

like image 22
Jani Hartikainen Avatar answered Nov 04 '22 21:11

Jani Hartikainen