This article is located on outdated, archived website. Please go to the new website to continue browsing. Thank you.

Open new website

The Performance Testing of ES6 Generators, ES6 Promises and Callbacks

Hi, guys. It’s going to be a short post.

I investigated the performance of the modern ES6 features and got an interesting result. For benchmarking I wrote the custom benchmark (you can try it here: GitHub). It allows to compare between each other the following features:

  • Async calls with callbacks
  • Async calls with an ES6 promise
  • Async calls with a Generator
    You can manage an amount of iterations, response time in the JS file. It’s hardcoded but exported to separated variables.

It works in a pretty simple way:

  • Draws DOM and calculates initial data
  • Starts benchmark for the first implementation
  • Try to make async action XXX times (you can define an amount of iterations)
  • Calculates time for the each iteration
  • Calculates the average value
  • Choose the second implementation…
  • Draws the results for all of the implementations

I got the following results.

Win 8.1 Chrome 51:

chrome-generators-benchmark

But there were some strange situations. Promises sometimes become slower than generators. Seems it depends on a memory amount, and this behavior is different when I trying to close some programs and minify PC overload.

Win 8.1 Firefox 47

firefox-generators-benchmark

Firefox handles generators faster than promises. And it’s a stable behavior. But firefox is stupidly slow. Seems, Mozilla should update their browser logo:

slowpoke

My MacBook is much less power, so I tried to run the benchmark on it too:

Chrome 51

mac-chrome-benchmark

As you can see, the picture is similar. The fastest way to make async call still be a Callback.