Promise then(resolve, reject) vs. then(resolve).catch(reject)

Benchmark created on


Description

This test compares the performance of handling both resolve and reject cases using two different Promise API patterns:

  1. promise.then(resolve, reject) - Passing both handlers to the 'then' method.
  2. promise.then(resolve).catch(reject) - Chaining 'catch' after 'then' for rejection.

Test runner

Ready to run.

Testing in
TestOps/sec
Resolved: then(resolve, reject)
var resolvedPromise = Promise.resolve(1);
resolvedPromise.then(function(value) {
      // Do nothing
    }, function(error) {
      // This should not be called
    });
ready
Resolved: then(resolve).catch(reject)
var resolvedPromise = Promise.resolve(1);
    resolvedPromise.then(function(value) {
      // Do nothing
    }).catch(function(error) {
      // This should not be called
    });
  
ready
Rejected: then(resolve, reject)
var rejectedPromise = Promise.reject(new Error('Test Error'));

rejectedPromise.then(function(value) {
      // This should not be called
    }, function(error) {
      // Do nothing
    });
ready
Rejected: then(resolve).catch(reject)
 var rejectedPromise = Promise.reject(new Error('Test Error'));
 
 rejectedPromise.then(function(value) {
      // This should not be called
 }).catch(function(error) {
      // Do nothing
 });
  
ready

Revisions

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