Benchmarking Yarn

It’s been four weeks already since Facebook open sourced Yarn, a fast, reliable and secure dependency manager for JavaScript.

I had been reading about and experimenting with it since the first day so I could share what I learned—which I did in the form of a tweet:

Well, yeah, and then there was that almost unnoticed tweet by Wes Bos:

As you can see, there definitley was an overwhelming interest in Yarn right from the start. 😀

I promised a follow-up post including first real-world tests, so this is it.

Preparation

In order to provide up-to-date benchmarks, I first updated both npm and Yarn. I then grabbed the project I chose for benchmarking: MultilingualPress. In case you want to redo the benchmarks on your own, this is the package.json file I used.

And this is the environmental situation:

  • Node.js v6.9.1
  • npm 3.10.9
  • Yarn 0.16.1
  • Dell XPS 15 9550 (2.6 GHz Intel Core i7, 16 GB 2133 MHz DDR4)

Benchmarks

The benchmarking itself followed pretty much what Facebook did for the Compare Yarn Performance page.

For each of the possible situations, I executed both npm and Yarn five times. The individually stated time is the average duration of all five respective measurements.

Besides the time to install, I also stated the size of the node_modules folder as well as the according manifest file for the two tools.

Time

Both npm and Yarn have been used to install all (dev) dependencies of MultilingualPress in all possible situations.

Empty Cache, node_modules Missing, Manifest Files Missing

npm (4m 3.545s)
Yarn (1m 4.656s)
Yarn is 3.767 times faster than npm, with a difference of 2m 58.889s.

Warm Cache, node_modules Missing, Manifest Files Missing

npm (3m 23.113s)
Yarn (0m 33.003s)
Yarn is 6.154 times faster than npm, with a difference of 2m 50.11s.

Empty Cache, node_modules Missing, Manifest Files Present

npm (1m 29.163s)
Yarn (1m 6.548s)
Yarn is 1.34 times faster than npm, with a difference of 0m 22.615s.

Warm Cache, node_modules Missing, Manifest Files Present

npm (1m 24.778s)
Yarn (0m 27.932s)
Yarn is 3.035 times faster than npm, with a difference of 0m 56.846s.

Empty Cache, node_modules Present, Manifest Files Present

npm (0m 6.258s)
Yarn (0m 0.738s)
Yarn is 8.48 times faster than npm, with a difference of 0m 5.52s.

Warm Cache, node_modules Present, Manifest Files Present

npm (0m 6.258s)
Yarn (0m 0.734s)
Yarn is 8.526 times faster than npm, with a difference of 0m 5.524s.

Warm Cache, node_modules Present, Manifest Files Missing

npm (0m 5.362s)
Yarn (0m 21.165s)
Yarn is 3.947 times slower than npm, with a difference of 0m 15.803s.

Empty Cache, node_modules Present, Manifest Files Missing

npm (0m 5.379s)
Yarn (1m 1.787s)
Yarn is 11.487 times slower than npm, with a difference of 0m 56.408s.

Size

When using npm, the size of the node_modules folder is 93,723 KiB, and the npm-shrinkwrap.json file is 177,370 B. Since MultilingualPress requires npm packages for development purposes only, the shrinkwrap file has been created via $ npm shrinkwrap --dev.

Using Yarn results in a node_modules folder of size 103,674 KiB, while the yarn.lock file is 175,147 B in size.

Let’s have a visual representation of that now:

Size Comparison npm and Yarn
Comparison of npm and Yarn: size of the node_modules folder (left), and the npm-shrinkwrap.json and yarn.lock file, respectively (right).
original scale by janjf93: Waage(license)

Conclusion

Yarn is fast!

Just like Facebook, I was able to prove Yarn’s superiority over npm, with a completely different project. Except for the situations where the node_modules folder is present, but the yarn.lock file is not, Yarn is way faster than npm.

In my case, using Yarn resulted in a slightly larger node_modules folder. With round about 10 MiB, which is 10.617%, this is quite acceptable, in my opinion. The difference between the manifest files can safely be ignored, although yarn.lock was the smaller of the two.

If you’re still using npm, you’re wasting time!

Are You Using Yarn Yet?

So, did you try Yarn yourself already?

How do you like (working with) it?

Did Yarn replace some other dependency manager that you were using before? Which one? And why?

Do you agree with my findings, or did you experience something different?

Leave a Reply

Your email address will not be published. Required fields are marked *