funkystuff

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var foo = { r: 123, g:222, b:3 };
   
    function rgb2hsb(rgb) {
        var hsb = { h: 0,       s: 0,   b: 0 };
        var min = Math.min(rgb.r, rgb.g, rgb.b);
        var max = Math.max(rgb.r, rgb.g, rgb.b);
        var delta = max - min;
        hsb.b = max;
        hsb.s = max != 0 ? 255 * delta / max : 0;
        if (hsb.s != 0) {
                if (rgb.r == max) {
                        hsb.h = (rgb.g - rgb.b) / delta;
                } else if (rgb.g == max) {
                        hsb.h = 2 + (rgb.b - rgb.r) / delta;
                } else {
                        hsb.h = 4 + (rgb.r - rgb.g) / delta;
                }
        } else {
                hsb.h = -1;
        }
        hsb.h *= 60;
        if (hsb.h < 0) {
                hsb.h += 360;
        }
        hsb.s *= 100 / 255;
        hsb.b *= 100 / 255;
   
        hsb.h = hsb.h | 0;
        hsb.s = hsb.s | 0;
        hsb.b = hsb.b | 0;
   
        return hsb;
    }
   
    function rgb2b(rgb) {
      return (rgb.r + rgb.g + rgb.b) / 3 / 255 * 100 << 0;
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
rgb2hsb
rgb2hsb(foo);
pending…
rgb2b
rgb2b(foo);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment