MessageChannel.vs.settimeout

JavaScript performance comparison

Test case created by Tac Huang

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    fn = function() {
      deferred.resolve();
    };
    var channel = new MessageChannel();
    // linked list of tasks (single, with head node)
    var head = {},
        tail = head;
    channel.port1.onmessage = function() {
      head = head.next;
      var task = head.task;
      delete head.task;
      task();
    };
    nextTick_messageChannel = function(task) {
      tail = tail.next = {
        task: task
      };
      channel.port2.postMessage(0);
    };
   
    nextTick_setTimeout = function(task) {
      setTimeout(task, 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
setTimeout
// async test
nextTick_setTimeout(fn);
pending…
MessageChannel
// async test
nextTick_messageChannel(fn);
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