PHP7とJava(Kotlin)のパフォーマンス比較メモ

#計測結果

"hoge"と出力するだけのプログラムでパフォーマンス比較を行ってみました。

CPU: Core i5 2500K
OS： MintLinux(VirtualBoxで実行)

結果は以下のとおり。単位はreq/secです。

| 計測項目         | php7     | php7+silex  | kotlin+JavaSpark |
|:---------------:|:---------:|:------------:|:---------------:|
|1並列 5000req    | 1368     | 416          |   3360          |
|100並列 5000req  | 3245     | 703          |  11021          |

Javaにはルーターの処理が入っているので、公平ではないためphpもsilex版を用意しています。

PHP7になって２倍の速度になったとはいえ、やはりJavaと比べると圧倒的な差がありますね。
最近ではphpでフレームワークを使わないことはありえないので、php7とjavaでは実質10倍以上の差がでることがわかります。

##apche2.4 + php7 + opcache

###Program
```php
<?php
echo "hoge"
```

###Result

```bash
ab -c 1 -n 5000 http://localhost:8080/

Concurrency Level:      1
Time taken for tests:   3.654 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      1015000 bytes
HTML transferred:       20000 bytes
Requests per second:    1368.45 [#/sec] (mean)
Time per request:       0.731 [ms] (mean)
Time per request:       0.731 [ms] (mean, across all concurrent requests)
Transfer rate:          271.28 [Kbytes/sec] received
```

```bash
ab -c 100 -n 5000 http://localhost:8080/

Concurrency Level:      100
Time taken for tests:   1.541 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      1015000 bytes
HTML transferred:       20000 bytes
Requests per second:    3245.63 [#/sec] (mean)
Time per request:       30.811 [ms] (mean)
Time per request:       0.308 [ms] (mean, across all concurrent requests)
Transfer rate:          643.42 [Kbytes/sec] received
```

##apche2.4 + php7 + opcache + Silex1.3

### Program

```php
<?php

require __DIR__ . '/vendor/autoload.php';

$app = new \Silex\Application();

$app->get('/',function(){
        return 'hoge';
});

$app->run();
```

###Result

```bash
ab -c 1 -n 5000 http://localhost:8080/silex.php

Concurrency Level:      1
Time taken for tests:   11.999 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      1375000 bytes
HTML transferred:       20000 bytes
Requests per second:    416.69 [#/sec] (mean)
Time per request:       2.400 [ms] (mean)
Time per request:       2.400 [ms] (mean, across all concurrent requests)
Transfer rate:          111.90 [Kbytes/sec] received
```

```bash
ab -c 100 -n 5000 http://localhost:8080/silex.php

Concurrency Level:      100
Time taken for tests:   7.107 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      1375000 bytes
HTML transferred:       20000 bytes
Requests per second:    703.55 [#/sec] (mean)
Time per request:       142.135 [ms] (mean)
Time per request:       1.421 [ms] (mean, across all concurrent requests)
Transfer rate:          188.94 [Kbytes/sec] received
```

##Kotlin Beta4 + JavaSpark2.4

### Program
```kotlin
import spark.Request
import spark.Response
import spark.Spark.*

fun main(args:Array<String>) {
    println("Hello World!")

    get("/", { req,res ->
        "hoge"
    })
}
```

###Result

```bash
ab -c 1 -n 5000 http://localhost:4567/

Concurrency Level:      1
Time taken for tests:   1.488 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      655000 bytes
HTML transferred:       20000 bytes
Requests per second:    3360.52 [#/sec] (mean)
Time per request:       0.298 [ms] (mean)
Time per request:       0.298 [ms] (mean, across all concurrent requests)
Transfer rate:          429.91 [Kbytes/sec] received
```

```bash
ab -c 100 -n 5000 http://localhost:4567/

Concurrency Level:      100
Time taken for tests:   0.454 seconds
Complete requests:      5000
Failed requests:        0
Total transferred:      655000 bytes
HTML transferred:       20000 bytes
Requests per second:    11021.25 [#/sec] (mean)
Time per request:       9.073 [ms] (mean)
Time per request:       0.091 [ms] (mean, across all concurrent requests)
Transfer rate:          1409.95 [Kbytes/sec] received
```