Last time i do many thing starting from small utilities and up to big projects in golang. And many friends ask me why… first time i just said that golang is simple and cool :) But now i decided to do simple benchmark to show why…
So, used interpreters/compilers:
PHP:
$ php --version
PHP 5.6.4-4ubuntu6 (cli) (built: Apr 17 2015 15:47:51)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
HHVM:
$ hhvm --version
HipHop VM 3.7.2 (rel)
Compiler: tags/HHVM-3.7.2-0-gfc9f29b2799933d8215faaadfa83de722df64e26
Repo schema: 34f16546e395aed44ad434467b6f96c89b0d8a8b
C:
$ gcc --version
gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Go:
$ go version
go version go1.4.2 linux/amd64
And all of this on laptop with i3-4030U CPU @ 1.90GHz and 16GB RAM
PHP (& HHVM) code:
<?php
$a = 0;
for ($i = 0; $i < 1000000000; $i++)
$a += $i;
print "$a\n";
C code:
int main()
{
long a = 0;
for (int i = 0; i < 1000000000; i++)
a += i;
printf("%ld\n", a);
return 0;
}
Go code:
package main
import (
"fmt"
)
func main() {
a := 0
for i := 0; i < 1000000000; i++ {
a += i;
}
fmt.Println(a)
}
And… results:
PHP:
User time (seconds): 68.01
System time (seconds): 0.09
Maximum resident set size (kbytes): 14628
HHVM:
User time (seconds): 37.40
System time (seconds): 0.08
Maximum resident set size (kbytes): 110144
GCC -O0:
User time (seconds): 4.06
System time (seconds): 0.03
Maximum resident set size (kbytes): 1372
GCC -O3:
User time (seconds): 0.48
System time (seconds): 0.00
Maximum resident set size (kbytes): 1404
GO:
User time (seconds): 0.52
System time (seconds): 0.00
Maximum resident set size (kbytes): 1632
And this is an answer why do i use go almost for anything :) Development is as simple as in PHP or Python, but resulting binary only a bit slower than plain C.
So as for me “application speed”/”development speed” is awesome for most cases.
P.S.: no Java, Scala, Python and other languages in benchmark only due to i don’t use them as often as C/C++/PHP/Go