But the "correct" way to do it would be
~$ echo 't=0;for (i=0; i<100000000; ++i) t+=i; console.log(t)' | time node
4999999950000000
2.01user 0.14system 0:01.70elapsed 126%CPU (0avgtext+0avgdata 40276maxresident)k
1968inputs+0outputs (15major+3370minor)pagefaults 0swaps
~$ (echo 'print(sum(range(100000000)))') | time python3
4999999950000000
1.89user 0.00system 0:01.90elapsed 99%CPU (0avgtext+0avgdata 9408maxresident)k
0inputs+0outputs (0major+1137minor)pagefaults 0swaps
Edit: Or a bit faster
~$ echo 'import numpy as np; print(np.sum(np.arange(100000000)))' | time python3
4999999950000000
0.27user 0.59system 0:00.87elapsed 99%CPU (0avgtext+0avgdata 807240maxresident)k
0inputs+0outputs (0major+102682minor)pagefaults 0swaps
You could argue that you should always know what is "the Pythonic way" and always do that.
But I like languages where even if you do things the wrong way, the long-winded way, build up everything yourself from first principles rather than knowing the right library or function to use ... it's still damned fast.
Interestingly, if I use Python more like the JavaScript then it's actually a bit faster:
Mac-mini:programs bruce$ (echo 't=0;i=0'; echo 'while i<100000000: t+=i;i+=1'; echo 'print t') | time python
4999999950000000
6.75 real 6.30 user 0.09 sys
Suggesting that the Python range() is not a generator like the one I built in JavaScript, but actually creates an array.
I also find it annoying that (as far as I know) there is absolutely no way to put the Python on a single line.
Well, ok, turns out you can tell echo (at least some versions) to allow embedding newlines:
$ echo -e 't=0;i=0\nwhile i<100000000: t+=i;i+=1\nprint t' | time python
4999999950000000
7.31 real 6.55 user 0.11 sys