Skip to content

Instantly share code, notes, and snippets.

@stqism
Last active August 29, 2015 14:02
Show Gist options
  • Save stqism/ccc9c5a932a6c45e5078 to your computer and use it in GitHub Desktop.
Save stqism/ccc9c5a932a6c45e5078 to your computer and use it in GitHub Desktop.
Holy fuck Python is slow
count = 0
while (count < 1000000000):
count = count + 1
fn main() {
let mut count = 0;
while count < 1000000000 {
count += 1;
}
}
sean@Soyuz:~/rust$ time python 1.py (Python optimizations only speed up loading)
real 7m10.859s
user 7m2.517s
sys 0m4.206s
sean@Soyuz:~/rust$ time ./1 (With -O)
real 0m0.006s
user 0m0.002s
sys 0m0.005s
4 seconds without optimizations.
Pretty sure rust is cheating, turning 10 million in to 10,000,000,000,000,000 takes 10 ms to run.
@tcosprojects
Copy link

for i in xrange(1000000000):
    pass
$ time python test.py 

real    0m18.114s
user    0m18.078s
sys     0m0.017s

Python is fast and doesn't cheat!

@nickvanw
Copy link

$ cat loop.c
main()
{
    int x;
    for (x = 0; x < 1000000000; x++) {
    }
}
$ gcc -O3 loop.c
$ time ./a.out

real    0m0.001s
user    0m0.000s
sys 0m0.000s
$ cat loop.pl
use strict;
use warnings;

for (my $i = 0; $i < 1000000000; $i++) {

}
$ time perl loop.pl

real    0m30.078s
user    0m30.092s
sys 0m0.000s
$ cat loop.go
package main

func main() {
    for i := 0; i < 1000000000; i++ {
    }
}
$ go build loop.go
$ time ./loop

real    0m0.333s
user    0m0.332s
sys 0m0.000s

microbenchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment