MessageChannel.vs.settimeout
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
setTimeout |
|
pending… |
MessageChannel |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments