Sunday, October 16, 2016

Comparing Nodejs v6 Vs PHP7 Performance Benchmarking

I will show you a comparison of performance between Nodejs and PHP. This is my PC configuration.



I will compare
===================
The version of NodeJS:  v6.4.0
The version of PHP   : PHP 7.0.8


Nodejs Code:

app.js
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
server.listen(8000);


PHP code

index.php

<?php

echo "Hello world";

Running the server:
===============
I have used node built-in http server to run the nodejs code
node app.js 
 the node server is running on http://localhost:8000

And I have used php built-in server to run the php code

php -S localhost:8080

the php server is running on http://localhost:8080


Benchmarking:
==================
I did benchmark with siege, and ran them on the same machine. To install siege on Ubuntu, you can run sudo apt-get install siege . First, I have run this test on node server


siege -q -c 100 -b -t 60s http://localhost:8000/

and got this result for Node:

Transactions:              572363 hits
Availability:              100.00 %
Elapsed time:               59.29 secs
Data transferred:            6.55 MB
Response time:                0.01 secs
Transaction rate:         9653.62 trans/sec
Throughput:                0.11 MB/sec
Concurrency:               99.83
Successful transactions:      572363
Failed transactions:               0
Longest transaction:            0.04
Shortest transaction:            0.00

Afterwards, I have ran the same test on php  server  by the following command


siege -q -c 100 -b -t 60s http://localhost:8080

and got this result for PHP:

Transactions:              443534 hits
Availability:              100.00 %
Elapsed time:               59.49 secs
Data transferred:            4.65 MB
Response time:                0.01 secs
Transaction rate:         7455.61 trans/sec
Throughput:                0.08 MB/sec
Concurrency:               99.74
Successful transactions:      443534
Failed transactions:               0
Longest transaction:            0.08
Shortest transaction:            0.00

Finally, we can see that NodeJS is more faster than PHP.