0

Small benchmark to compare performance of PHP, NodeJS and Golang

Hello everyone,

Golang is said that has a great performance. So I decide to create a small benchmark to compare performance of PHP, NodeJS, and Golang.

My Environment

  • MacOS 3.1 GHz Intel Core i5
  • PHP 7.2.6
  • NodeJS 10.7.0
  • Go 1.11.2

Implementation code

PHP Code

function calc($total) {
	$before = microtime(true);
	$sum = 0;
	for ($i = 0; $i < $total; $i++) { 
		$sum += $i;
	}

	$after = microtime(true);

	echo (round($after - $before, 3) * 1000);
	echo "\n";
}

NodeJS Code

function calc(total) {
	var before = Date.now(),
		sum = 0;

	for (var i = 0; i < total; i++) {
		sum += i;
	}

	var after = Date.now();

	console.log(after - before);
}

Golang Code

func calc(total int) {
	before := time.Now().UnixNano()
	sum := 0
	for i := 0; i < total; i++ {
		sum += i
	}
	after := time.Now().UnixNano()
	fmt.Println((after - before) / 1000000)
}

Benchmark

No. Calculations (total) PHP NodeJS Golang
500M 8064ms 594ms 222ms
1B 15821ms 1178ms 319ms
10B 170337ms 11889ms 3179ms

All rights reserved

Bình luận

Đăng nhập để bình luận
Avatar
@socoladaica
thg 11 16, 2018 9:06 SA

gấp hơn 10 lần luôn, ghê thật

Avatar
@oliverusselldev
thg 11 20, 2018 2:56 CH

PHP performance really depends on how you have configured your website and what packages you are using. For example, if you are using memcached, redis and others for performance, you will get better performance when you are conducting php performance test on your website.

Avatar
@loizenai
thg 11 29, 2020 5:10 CH
Avatar
@loizenai
thg 11 29, 2020 5:12 CH
Avatar
0
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí