1234567213

JavaScript performance comparison

Revision 7 of this test case created by Esailija

Preparation code

<script>
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>
var NodeEmitter = module.exports;
</script>
<script type="text/javascript" src="https://rawgithub.com/petkaantonov/FastEmitter/master/fastemitter.js">
</script>
<script>
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

<script type="text/javascript" src="https://rawgithub.com/joyent/node/master/lib/events.js"> </script> <script> var NodeEmitter = module.exports; </script> <script type="text/javascript" src="https://rawgithub.com/petkaantonov/FastEmitter/master/fastemitter.js"> </script> <script> 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>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
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.

0 Comments