Home > Uncategorized > PHP 5.5 vs HHVM vs Node.js Benchmark part 4

PHP 5.5 vs HHVM vs Node.js Benchmark part 4

In this set of benchmarks I am comparing the performance of node vs hhvm in doing what a lot of web apps do: Adding something to a database and reading something from a database and then making a webpage out of. As expected given most of the time is spent waiting on the database node and hhvm perform similarly.

Node.Js

Concurrency Average Time
10 37.713
100 39.163
200 39.408
300 38.436
400 43.051
500 37.378
600 38.983
700 37.487
800 42.552
900 39.468

node_database

HHVM

Concurrency Average Time
10 37.554
100 39.794
200 37.862
300 41.682
400 39.824
500 37.555
600 42.187
700 37.644
800 38.217
900 37.825

php_database

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Load the http module to create an http server.
var http = require('http');
 
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/html"});
  getData(response);
 
});
server.listen(3000);
 
//server.listen(80);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:3000/");
 
var mysql  = require('mysql');
var pool  = mysql.createPool(
{
 host: "127.0.0.1",
 user: "someone",
 password: "nothing",
 database: "test",
 port: 3306
});
 
function getData(res){
 var data;
 pool.getConnection(function(err,conn){
   console.log("In get Connection");
   if(err){
     console.log(err);
     return;
   }
   conn.query("select * from users", function(err,rows,fields){
   //console.log(rows);
 
     console.log("In first query");
     console.log(fields);
     console.log(createTable(rows));
     res.write(createTable(rows));
     conn.query("update `users` set `age`=FLOOR(RAND()*100) where 1",function(err,result){
       console.log("Update result: " + result);
	 conn.query("select * from users", function(err,rows){
           res.end(createTable(rows));  
           conn.release();
         });
 
 
     });
   });
 });
}
 
function createTable(results)
{
    console.log("In create Tables");
    console.log(results);
    if (results.length==0) {
        return '<table><tr><td>Empty Result Set</td></tr></table>';
    }
 
    // dynamically create the header information from the keys
    // of the result array from mysql
    table = '<table>';
    keys = Object.keys(results[0]);
    table+='<thead><tr>';
    keys_fixed = [];
    console.log("In create keys");
    console.log(keys.length);
 
    for(var i=0; i<keys.length; i++){
      table+='<th>'+keys[i]+'</th>';
    }
 
    console.log("End create keys");
 
    table+='</tr></thead>';
 
    // populate the main table body
    table+='<tbody>';
    for (var i=0; i<results.length;i++) {
	result = results[i];
 
        console.log("Result");
        console.log(result);
        table+='<tr>';
        for(var j=0; j<keys.length; j++){  
          //console.log(key);  
          table+='<td>'+result[keys[j]]+'</td>';
        }
        table+='</tr>';
    }
    table+='</tbody></table>';
    console.log("Out of create tables");
    return table;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
function main(){
 $db = new PDO("mysql:host=localhost;dbname=test","nothing","nothing",array(
    PDO::ATTR_PERSISTENT => true
));
 $stmt = $db->query("select * from users");
 
 
 $res = $stmt->fetchAll();
 #print_r($res);

 
 echo createTable($res);
 
 
 $db->query("update `users` set `age`=FLOOR(RAND()*100) where 1");
 
 $stmt = $db->query("select * from users");
 
 
 $res = $stmt->fetchAll();
 
 echo createTable($res);
}
function createTable(array $results = array())
{
    if (empty($results)) {
        return '<table><tr><td>Empty Result Set</td></tr></table>';
    }
 
    // dynamically create the header information from the keys
    // of the result array from mysql
    $table = '<table>';
    $keys = array_keys(reset($results));
    $table.='<thead><tr>';
    $keys_fixed = array();
    for($i=0; $i<count($keys); $i+=2){
      $table.='<th>'.$keys[$i].'</th>';
      $keys_fixed[]=$keys[$i];
 
    }
 
    $table.='</tr></thead>';
 
    // populate the main table body
    $table.='<tbody>';
    foreach ($results as $result) {
        $table.='<tr>';
        foreach ($keys_fixed as $key) {
            $table.='<td>'.$result[$key].'</td>';
        }
 
        $table.='</tr>';
    }
    $table.='</tbody></table>';
    return $table;
}
 
 
main();
Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.


− 8 = zero