Node vs. Deno

Testing performance of two JS Runtimes environments

Agustín Ramos, Dario Renzuli and Victor Hugo Valle Castillo are Software Engineers from the Cognizant Softvision Web Community in the Buenos Aires studio. Together, they’ve been experimenting with Deno, the new JS Runtime environment from the creator of Node.js. In their first article, the engineers shared their conclusions after demoing Deno.land. Here, they share their findings after comparing the performance between Deno and Node.js.

Processing Speed (Node.js vs Deno)

This was one of our major objectives during all these tests. As such, we created two apps for this purpose, one with Node.js based on Express, and the other one for Deno, both apps have the same endpoints and do exactly the same, in other words, both have the same purpose.

Since during the first part of this series we had a good experience with both runtimes, we decided to wait a bit in order to perform all the tests with the last stable version for each one.

Note:

This article is aimed to show relevant information and some details about the processing speed in both runtimes. While this article does not reveal how to create an app from scratch, everyone is encouraged to dive in each repo to look into how each app works.

Node.js app (v14.2.0):

The dependencies installation took almost six seconds; it may vary depending on internet bandwidth.

The app started running without asking for additional permissions, e.g: for reading, writing or for running in the network.

Perform a GET request (fetch data from SWAPI):

It took approximately two seconds – one second since the request was performed and another one for fetching data from the external API. (Not bad!)

GET people

Speed details for fetched data (a list of 82 records):

Perform a POST request (write data creating a writeStream using the fetched data from SWAPI):

For making more interesting this test, we can multiply by twenty all the 82 objects retrieved within the results property, then we’ll have a list of 1640 records to assign to the POST method, we can even pass data within a .json file, for this example, we added that data on a people_src.json file, e.g:

POST people

The process ran really fast, it took less than a second (7.183 ms). The details are shown in the console.

Deno app (v1.0.0):

The first time running the app may take between six and 10 seconds, it depends on the internet bandwidth. As we discussed in the previous chapter, Deno installs and catches all the dependencies and starts running the app with a single run. Unlike Node.js, Deno requires permissions explicitly for accessing to the network, for reading and writing in the filesystem, otherwise, we’ll get something like this:

In order to start running the app correctly, we need to set the respective permissions as follows:

Perform a GET request (fetch data from SWAPI):

This time we were surprised. Unlike the previous tests we performed with the unstable versions of Deno where it was faster than Node.js, this time It took approximately three seconds – one second more than Node.js to request the same data from the external API.

Note:

We must bear in mind that we are requesting data to an external API, so the response may be affected based on the external API performance. We believe that in this scenario and for this test it is not a big deal because we are treating with an uncontrolled resource.

GET people (deno)

Speed details for fetched data (a list of 82 records):

 

Perform a POST request (write data creating a writeStream using the fetched data from SWAPI):

Note:

In order to write data in the filesystem we need to enable the respective flag when we start running the app, e.g:

As the test we performed before with Node.js, we used the same file containing the 1640 records, then we assign the .json file to the POST request, e.g:

POST people (deno)

The process ran super fast! It was almost six times faster than Node.js, taking less than a second (1.005 ms). The details are shown in the console.

 

Thinking out loud:

In both apps (Deno and Node) we got an additional resource in order to request a single record by id. We considered it was not necessary to include them in this test case due to the response depends on the external resource, but everyone can perform this test on their own, cloning each repo and running the app respectively.

Conclusions:

Both runtimes are really great. On one hand, we have Node.js which has a wide community and a good maturity up to now. On the other hand, we have Deno, a recent project with a small community enjoying its first stable release; it’s a very promised project based on its basics (security and speed) and for what it offers.

We like both, and of course, we’d definitely use both if we have the chance to create a real app.

Additional Resources: