(no title)
no_gravity | 5 years ago
For the first benchmark, I added a combined string length calcuclation:
def main():
r = 0
for j in range(20):
for i in range(1000000):
r += len(str(i))
print(r)
main()
When I execute it: time python3 test.py
I get 8.3s execution time.The PHP equivalent:
<?php
function main() {
$r = 0;
for ($j=0;$j<20;$j++)
for ($i=0;$i<1000000;$i++)
$r += strlen($i);
print("$r\n");
}
main();
When I execute it: time php test.php
Finishes in 1.4s here. So about 6x faster.Executing the Python version via PyPy:
time pypy test.py
Gives me 0.49s. Wow!For better control, I did all runs inside a Docker container. Outside the container, all runs are about 20% faster. Which I also find interesting.
Would like to see how the code performs in some more languages like Javascript, Ruby and Java.
iruoy|5 years ago
steveklabnik|5 years ago
dralley|5 years ago
This is fairly well known and if it's a bottleneck in your program the recommendation is to acquire the lock yourself and then write directly to stdout.
eggsnbacon1|5 years ago
hu3|5 years ago
I'd wager it will reach similar performance than pypy.
[1] https://stitcher.io/blog/new-in-php-8
winrid|5 years ago
This will be amazing when it happens.