funnel.js vs vanilla

JavaScript performance comparison

Test case created by Saral

Info

Checking the performance of funnel.js vs vanilla JS

Preparation code

<script src="//cykeprojects.com/libraries/funnel/funnel-0.1.min.js"></script>

<script type="text/javascript">
var funnel = Funnel
    ("width: number, height: number?, units: string?")
    .default(function height(width) {
        return width;
    })
    .in("units", ["px", "em"])
    .set(["width", "height"], function(units) {
        return this() + units;
    })
(function(width, height) {
    var style = {}
    style.width = width;
    style.height = height;

    return style;
});

var vanilla = function(options) {
   var o = options || { };      
   o.units = o.units || 'px';
   if(['px', 'em'].indexOf(o.units) === -1) throw new Error('invalid unit type');

   var style = {};
   if(o.width || o.width === 0) {
        style.width = o.width + o.units;
   }    
   if(o.height || o.height == 0) {
        style.height = o.height + o.units;
   }

   return style;
}
</script>
<script>
Benchmark.prototype.setup = function() {
    var width = Math.floor(Math.random() * 100);
    var height = Math.floor(Math.random() * 100);
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
funnel.js
var style = funnel({
    width: width,
    height: height
});
pending…
vanilla
var style = vanilla({
    width: width,
    height: height
});
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment