Tornado vs Node.js

Posted on October 28, 2015

Nowadays Node.js is getting more and more popular, so I decided to compare it with some other server – Tornado. The first one is written in JavaScript, the latter in Python, so the outcome should be obvious. But is it? Let’s find out!

In my comparison I have used 3 kinds of tests:

  • Writing to the file
  • Finding prime numbers
  • Saving records in the database and then deleting them.

The test involved creating a new file, writing „hi there” into it and then saving it 10 000 times this way.

 

Tornado
Node.js

Due to the nature of JS, test had to be written recursively, which takes a little more code.
Time table below:

 

Tornado Node.js
1.35764789581 s

1.6857779026 0s

1.37607693672 s

1.67473793030s

2.138000011444092 0s

2.1540000438690186 s

1.991999864578247 0s

2.0950000286102295s

 

As you can see Tornado is faster by a whole second, which can be crucial in some cases.
The second test aims to measure the productivity of compared languages. We will use the Erathosteneses algorithm, where n = 1000000 – which really means “look for prime numbers until you reach 1 million”.

Tornado
Node.js

Time table:

Tornado Node.js
0.221151828766 s

0.216292858124 s

0.217554092407 s

0.320231914520s

0.10199999809265137s

0.06399989128112793s

0.08500003814697266s

0.08800005912780762s

 

As you can see, in this case Node.js is a lot faster, even while comparing the Node’s worst time (0,1019s) with Tornado’s best (0,2162).

 

Now for the last test – saving to the base. Nearly everybody in the web, uses databases. To test Node.js I used MongoDB database and for Tornado I have chosen MySql.

The test was very simple – save 10 000 records to the database and then delete them.

Tornado
Node.js

Although append in Python works terribly slow, the code is a lot more understandable.

Time table:

Tornado Node.js
0.283309936523 s

0.415552854538 s

0.343837976456 s

0.262784957886s

0.41499996185302734 s

0.24499988555908203 s

0.2350001335144043 0s

0.24099993705749512s

 

It looks pretty even here, but Node.js is slightly faster.

I can’t say a bad word about Node.js – it works fast and effectively, so if someone likes JS, I would also recommend Node.js. Personally I don’t like it and wanted for it to be as bad as possible, but unfortunately it’s not.

Junior PHP Developer