stats.js

July 7th 2010

Some of you may have realised already that I've been using a Javascript FPS counter on some of my experiments.

Originally it had exactly the same look as the Actionscript version but, as far as I know, you can't query the system to get the amount of memory the application is using from Javascript. So 2 of the 4 common values of the Actionscript version were empty. That made me reconsider the design and tried to improve it a bit. And after using it for quite a while I think it's ready.



As you can see it has two modes, FPS and MS. Just click on the widget to switch between them. I may change MS to use greens instead of cyan to match the Actionscript version a bit more. Thoughts?

Unfortunately this time the code is not as simple as the Actionscript version, but I think it's still simple enough.

var stats = new Stats();
parentElement.appendChild(stats.domElement);

setInterval(function () {

    stats.update();

}, 1000/60);

Find the source code, compressed file and more examples at the project page on github.

15 comments written so far...

Thanks for this component, helps me a lot. For your info: I've found that IE chokes on the implementation of Stats, and put the code above in a try / catch block.
July 7th 2010
Monokai
Is that IE9? Or IE8-? (Not a fan of adding browser specific code/detection stuff ;P)
July 7th 2010
mr.doob
Actually in Google Chrome you can query the memory usage. Here is one I ported from AS3 as well for my JS experiments.

http://www.coursevector.com/projects/orion/jsdemo/
July 7th 2010
Gabriel
Wow, didn't now that! :) Also, really nice port! Do you mind if I include it in the main repository?

http://github.com/mrdoob/Hi-ReS-Stats
July 7th 2010
mr.doob
Only briefly tried Stats in IE8, looks like addEventListener & canvas calls are incompatible with IE.
July 8th 2010
Monokai
execellent!!!
but remeber you've already übber surpassed the expectations of javascript from its conception feel comfortable with things like this, shit happens.
:(

"you can't query the system to get the amount of memory the application is usin"
July 10th 2010
JaK
JaK, what about reading the comments? Turns out you can.
July 10th 2010
mr.doob
%20AND%201=1
August 30th 2010
anonymous
%20AND%201=2
August 30th 2010
anonymous
AND 1=1/*
August 30th 2010
anonymous
AND 1=2/*
August 30th 2010
anonymous
' AND '1'='1
August 30th 2010
anonymous
' AND '1'='2
August 30th 2010
anonymous
' AND 1=1/*
August 30th 2010
anonymous
' AND 1=2/*
August 30th 2010
anonymous

Have your say!

Name:

Website:

Comment:

Some of the projects that I worked on.



Some of the HTML5 and Actionscript experiments I've done.