Giter Site home page Giter Site logo

resolved-promise-performance's Introduction

Benchmark

What is the overhead of requesting a value from a resolved promise?

Motivation

For a static value that is retrieved asynchronously subsequent calls return the same known value: what is the performance cost once it can be furnished as an already resolved promise?

For example a static data-point retrieved from some data-source is always retrieved as a promise. The first retrieval will incur asynchronous penalty as the value is unknown. What about subsequent retrievals? We're still using promises in an asynchronous call, but what's the cost?

Running

npm install
node index.js

Results

donePromise x 186,285 ops/sec ±39.04% (17 runs sampled)
value x 220,988 ops/sec ±19.03% (11 runs sampled)
fn x 80,614 ops/sec ±137.75% (10 runs sampled)
fastest :: value,donePromise,fn

donePromise x 171,476 ops/sec ±31.84% (13 runs sampled)
value x 183,915 ops/sec ±43.85% (11 runs sampled)
fn x 30,836 ops/sec ±192.23% (9 runs sampled)
fastest :: donePromise,value,fn

Retrieval from a resolved promise is almost as fast as retrieval of the value sans Promise wrapper.

Note that all tests are asynchronous calls--even when the value could be returned synchronously. This is to mimic the fact that resolved promises can only be used in asynchronous call handlers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.