Google’s “go” simple & stupid benchmark (2nd round: memspeed)

Continued from Round 1: I/O

Thanks to Juanval for the suggestion.

$ cat hello.cpp && g++ hello.cpp &&
> time for i in $(seq 10); do ./a.out; done
int main (int argc, char** argv)
{
    const int size = 250;
    int a[size],b[size],c[size];
    for(int i=0;i<size;++i)
        for(int j=0;j<size;++j)
            for(int k=0;k<size;++k)
                c[k]+=a[i]*b[j];
}
real	0m1.041s
user	0m0.944s
sys	0m0.020s

$ cat hello.py &&
> time for i in $(seq 10); do python hello.py; done
size = 250
a,b,c = [0]*size, [0]*size, [0]*size
for i in a:
    for j in b:
        for k in range(0,size):
            c[k] += i*j
real	1m7.210s
user	1m4.924s
sys	0m0.084s

$ cat hello.go && 8g hello.go && 8l hello.8 &&
> time for i in $(seq 10); do ./8.out; done
package main
func main()
{
    var a,b,c [250]int;
    for i := range a
    {
        for j := range b
        {
            for k := range c
            {
                c[k] += a[i] * b[j];
            }
        }
    }
}
real	0m3.000s
user	0m2.812s
sys	0m0.020s

Tags: [en, es] | November 12th, 2009 |

9 Responses to “Google’s “go” simple & stupid benchmark (2nd round: memspeed)”

  1. juanval Says:

    Holy crap, python really chokes on that one! I suspect that might be because of the “for i in a” syntax.

    Anyway, Go here takes “just” 3 times that of C++. Not half bad… but definitely not for high performance computing…

  2. stenyak Says:

    Yeah, python really sucked in this one.

    Some pythoners will probably blame me for not knowing how to code (which is probably true). But hey, I just learned Go and it’s already 20 times faster. Let’s say development time is also a part of this benchmark 😀

    Anyway, out of curiosity, I researched how to optimize the python version. Tried a different syntax, tried some lambda functions, looked for alternative math libs, and i finally stumbled upon NumPy, which improves the situation. Ironically, NumPy core is coded in C. Pwnage.

  3. stenyak.com » Blog Archive » Google’s “go” simple & stupid benchmark (1st round: I/O) Says:

    […] in Round 2: memspeed Tags: computing, rant [en, es] | November 11th, 2009 […]

  4. binder Says:

    Realistically 3x slower is the same speed. Over a range of benchmarks they will probably swap places.

    They have merged python and erlang… ehh… not that exciting.

  5. kazbayadum Says:

    C++ wins again! ^^

  6. binder Says:

    managed to get some of the benchmark game tests run.
    This is the go runtime as a percentage of the c runtime.
    nbody 1087
    threadring 6.32
    binarytree 175
    fannkuch 388
    spectralnorm 397
    mandelbrot 472
    meteor 232
    chameneos 49

  7. Matthias Says:

    These aren’t equivalent tests. The C code doesn’t zero the memory, there’s some overhead loading the runtime, etc. Testing longer runs would get you closer, too. The 8g compiler isn’t exactly their speedy implementation either. It’s their research implementation feeding into a 10-year-old backend. GCC is a wee bit more optimized. Their gcc frontend will be faster.

  8. stenyak Says:

    I’ve tried zeroing the memory in the C version, and it doesn’t provoke any noticeable change on the results. Maybe if i run it a million times i’ll find out it’s 0.01% slower, but after 10 tests it does not make much difference:

    $ cat hello.cpp && g++ hello.cpp && time for i in $(seq 10); do ./a.out >/dev/null ; done
    #include
    int main (int argc, char** argv)
    {
    const int size = 250;
    int a[size] = {0};
    int b[size] = {0};
    int c[size] = {0};
    for(int i=0;i

  9. Justin L Says:

    no error there with python, anything you do in python will either be A) logic written in C that’s just invoked by python, or B) shockingly slow if your domain-specific logic is actually written in python

Leave a Reply