Skip to content

Instantly share code, notes, and snippets.

@vinyvicente
Last active May 15, 2019 17:05
Show Gist options
  • Save vinyvicente/821d3c2cb27f14ae22bf587d17980dfd to your computer and use it in GitHub Desktop.
Save vinyvicente/821d3c2cb27f14ae22bf587d17980dfd to your computer and use it in GitHub Desktop.
Benchmark PHP 7.3.5 vs Node 12.1.0

PHP

Last login: Wed May 15 10:34:29 on ttys001
Vinicius-MacBook:~ vinyvicente$ wrk -t4 -c400 -d10s http://127.0.0.1:1337/
Running 10s test @ http://127.0.0.1:1337/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.78ms    1.55ms  23.47ms   82.95%
    Req/Sec     0.90k   458.32     1.57k    69.44%
  16192 requests in 10.05s, 2.49MB read
  Socket errors: connect 0, read 830, write 0, timeout 0
Requests/sec:   1611.70
Transfer/sec:    253.40KB
Vinicius-MacBook:~ vinyvicente$ php -v
PHP 7.3.5 (cli) (built: May  2 2019 12:42:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.5, Copyright (c) 1999-2018, by Zend Technologies
Vinicius-MacBook:~ vinyvicente$

Node JS

Vinicius-MacBook:~ vinyvicente$ wrk -t4 -c400 -d10s http://127.0.0.1:1337/
Running 10s test @ http://127.0.0.1:1337/
  4 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    19.76ms    5.91ms  68.61ms   67.83%
    Req/Sec     4.17k   560.07     5.08k    89.00%
  166075 requests in 10.01s, 31.99MB read
  Socket errors: connect 0, read 427, write 0, timeout 0
Requests/sec:  16595.81
Transfer/sec:      3.20MB
Vinicius-MacBook:~ vinyvicente$ node -v
v12.1.0
@vinyvicente
Copy link
Author

vinyvicente commented May 15, 2019

<?php

require 'vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$server = new React\Http\Server(function (Psr\Http\Message\ServerRequestInterface $request) {
    return new React\Http\Response(
        200,
        array('Content-Type' => 'text/plain'),
        "Hello World!\n"
    );
});

$socket = new React\Socket\Server(1337, $loop);
$server->listen($socket);

echo "Server running at http://127.0.0.1:1337\n";

$loop->run();
var http = require('http');

var data = {
  'code': 'ok',
  'error': false,
  'payload': 'Hello World'
};

var app = function (req, res) {
  res.writeHead(200, {
    'Content-Type': 'application/json'
  });
  res.end(JSON.stringify(data));
};

var server = http.createServer(app);

server.listen(1337, function() {
  console.log("Server running at http://127.0.0.1:1337");
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment