Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

計測結果

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

apche2.4 + php7 + opcache

Program

<?php
echo "hoge"

Result

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
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

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

$app = new \Silex\Application();

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

$app->run();

Result

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
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

import spark.Request
import spark.Response
import spark.Spark.*

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

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

Result

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
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
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした