1234567213

JavaScript performance comparison

Revision 7 of this test case created by Esailija

Info

Single identifier named listener

Preparation code

<script type="text/javascript">
var global = window;
var require = function(val) {
    if( val == "util") {
        return {
            isNumber: function( arg ) {
                 return typeof arg === 'number';
            },
            isUndefined: function( arg ) {
                return arg === void 0;
            },
            isFunction: function( arg ) {
                return typeof arg === "function";
            },
            isObject: function( arg ) {
                return typeof arg === 'object' && arg !== null;
            }
        }
    }
};
var module = {};
</script>
<script type="text/javascript" src="https://rawgithub.com/joyent/node/master/lib/events.js">
</script>
<script type="text/javascript">
var NodeEmitter = module.exports;
</script>
<script type="text/javascript" src="https://rawgithub.com/petkaantonov/FastEmitter/master/fastemitter.js">
</script>
<script type="text/javascript">
var FastEmitter = module.exports;

var a = new FastEmitter();
var b = new NodeEmitter();
if( !Array.isArray(a._events ) ) alert("modules are not loaded correctly");
if( !b._events ) alert("modules are not loaded correctly");
</script>
<script>
Benchmark.prototype.setup = function() {
    var sum = 0;
    var nodeEmitter = new NodeEmitter();
    var fastEmitter = new FastEmitter();
    var adder = function() {
        sum++;
    };
    nodeEmitter.on("event", adder);
    fastEmitter.on("event", adder);
};

Benchmark.prototype.teardown = function() {
    if( sum === 0 ) {
         throw new Error("not working");
    }
};
</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
node emitter
nodeEmitter.emit("event");
pending…
fast emitter
fastEmitter.emit("event");
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