|
|
|
|
|
by e12e
3643 days ago
|
|
Eh... cat<<eof > float.py
import itertools
s = sum(itertools.repeat(1.0, 100000000))
print(s)
$ time python float.py
100000000.0
real 0m0.602s
user 0m0.596s
sys 0m0.004s
time python3 float.py
100000000.0
real 0m0.603s
user 0m0.600s
sys 0m0.000s
$ time pypy float.py
100000000.0
real 0m0.211s
user 0m0.088s
sys 0m0.004s
That's with no warmup for the pypy variant (or indeed the other python variants). Or, slightly more "robust": $ python -m timeit -s "import itertools as i" \
"sum(i.repeat(1.0, 100000000))"
10 loops, best of 3: 594 msec per loop
$ python3 -m timeit -s "import itertools as i" \
"sum(i.repeat(1.0, 100000000))"
10 loops, best of 3: 592 msec per loop
$ pypy -m timeit -s "import itertools as i" \
"sum(i.repeat(1.0, 100000000))"
10 loops, best of 3: 68.2 msec per loop
Pypy actually does pretty good here: $ cat float.cpp
#include<iostream>
int main() {
double s = 0;
for (int i = 0; i < 100000000; ++i) {
s++;
}
std::cout << s << std::endl;
return 0;
}
$ g++ --std=c++14 -O3 float.cpp
$ time ./float
1e+08
real 0m0.237s
user 0m0.236s
sys 0m0.000s
Note that the C++ code use a loop, not a lazy generator. Apparently they may be coming in c++17 as proposal N4286. |
|
Personally, I think people often go quite overboard with the "benchmarks are useless" idea, but this benchmark really is useless, because it will never produce any differences betweens JITs and thus can't show whether one is good or bad.