Francesco Gusella
Francesco Gusella

Reputation: 33

CPU and memory usage of a file javascript

I did my first canvas, and you can see it here My Canvas. The main idea of this canvas is that when you go with the cursor against the points they escape from it. What I want now is to know how much my canvas will use the resources of the user's PC. For example, the RAM, the CPU or GPU. In particular, in my script there is a function called every 7ms:

setInterval (spiderFree, 7);

I wonder how this can be expensive for a computer. However the question is, how can I control the expenditure of computer resources due to my script?

Upvotes: 2

Views: 1332

Answers (2)

Alex
Alex

Reputation: 4934

You should take a look at this article from Paul Irish on his requestAnimationFrame cross-browser shim.

It will firstly try to optimise frames based on browser capability, and also, have backwards compatibility for old, non-GPU enabled browsers.

From the jQuery ticket:

Benefits:

  • let the browser choose the best 'animation tick' rate (instead of our arbitrary 13ms)

  • greatly reduce animation CPU usage when switching tab

  • helps keep animation synchronized

  • Full list of claimed benefits here

This is the 'industry standard' way of ensuring the best possible frame rate and resource utilisation of your animations.

Upvotes: 2

BoffinBrain
BoffinBrain

Reputation: 6525

In addition to Alex's good answer, bear in mind that you can use Firefox's developer tools (F12). You can use the Performance tab to see exactly how long your code is taking to execute, and which parts take the longest. You can also use the Canvas tab to analyze the frames. (You'll need to enable these features from the Settings tab).

Upvotes: 0

Related Questions