One billion is not a very big number. Any reasonably modern machine should be able to do this in a few seconds at most, if it's able to do the work with native types. I verified this by writing an equivalent C program, reading the assembly to make sure that it actually was doing addition, and timing it (it completes in about 1.8 seconds on my machine).
Python, however, doesn't have a concept of natively typed variables (or meaningful type annotations at all), so it has to do hundreds of times as much work in this case. In short, the answer to your headline question is "yes". Go really can be that much faster than Python, even without any kind of compiler trickery like optimizing away a side-effect-free loop.
Answer from hobbs on Stack OverflowGo Performs 10x Faster Than Python
performance - Can Go really be that much faster than Python? - Stack Overflow
When you guys use Python or Go ?
Go vs Python, employability for a grad / junior dev?
Videos
Doing some digging around the Debian Computer Language Benchmark Game I came across some interesting findings. After grabbing the data off the page and cleaning it up with awk and sed, I averaged out the CPU seconds ('secs') across all tests including physics and astronomy simulations (N-body), various matrix algorithms, binary trees, regex, and more. These may be fallible and you can see my process here
Here are the results of a few of my scripts which are the average CPU seconds of all tests. Go performs 10x faster than Python and is head to head with Java.
Python Average: 106.756 Go Average: 8.98625 Java Average: 9.0565 Go Average: 8.98625 Rust Average: 3.06823 Go Average: 8.98625 C# Average: 3.74485 Java Average: 9.0565 C# Average: 3.74485 Go Average: 8.98625
One billion is not a very big number. Any reasonably modern machine should be able to do this in a few seconds at most, if it's able to do the work with native types. I verified this by writing an equivalent C program, reading the assembly to make sure that it actually was doing addition, and timing it (it completes in about 1.8 seconds on my machine).
Python, however, doesn't have a concept of natively typed variables (or meaningful type annotations at all), so it has to do hundreds of times as much work in this case. In short, the answer to your headline question is "yes". Go really can be that much faster than Python, even without any kind of compiler trickery like optimizing away a side-effect-free loop.
pypy actually does an impressive job of speeding up this loop
def main():
x = 0
while x < 1000000000:
x+=1
if __name__ == "__main__":
s=time.time()
main()
print time.time() - s
$ python count.py
44.221405983
$ pypy count.py
1.03511095047
~97% speedup!
Clarification for 3 people who didn't "get it". The Python language itself isn't slow. The CPython implementation is a relatively straight forward way of running the code. Pypy is another implementation of the language that does many tricky (especiallt the JIT) things that can make enormous differences. Directly answering the question in the title - Go isn't "that much" faster than Python, Go is that much faster than CPython.
Having said that, the code samples aren't really doing the same thing. Python needs to instantiate 1000000000 of its int objects. Go is just incrementing one memory location.