bind vs new fn

Benchmark created by Bill on


Setup

function makeShoppingCart ({
    db
  }) {
    return Object.freeze({
      addProduct,
      empty,
      getProducts,
      removeProduct
    })
    function addProduct (product) {
      db.push(product)
    }
    
    function empty () {
      db = []
    }
  
    function getProducts () {
      return Object
        .freeze(db)
    }
  
    function removeProduct (id) {
      // remove a product
    }
  }

Test runner

Ready to run.

Testing in
TestOps/sec
bind
const cart = makeShoppingCart({db: []})
const empty = cart.empty.bind(cart)
ready
new fn
const cart = makeShoppingCart({db: []})
const empty = () => cart.empty()
ready

Revisions

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