|
|
|
|
|
by dzderic
4723 days ago
|
|
A while loop and temporary mutable variables are definitely not the Pythonic way of doing this. More idiomatic: $ time python -c 'print sum(xrange(100000000 + 1))'
5000000050000000
real 0m1.398s
user 0m1.383s
sys 0m0.012s
Comparison to baseline: $ time (echo -e 'n=0 \ni=0 \nwhile (i <= 100000000): \n n += i \n i += 1 \n\nprint(n)\n' | python)
5000000050000000
real 0m33.140s
user 0m32.939s
sys 0m0.023s
|
|