News for hackers. Stuff that matters.
Re:Python consumes 38x more energy than Java by mg on Thursday July 13, 2023 @07:19AM (#36707502)
Is Python's "values don't change, they get replaced by new ones stored elsewhere" approach what makes it slow?

I would like to see some micro-benchmarks which pin down the bottlenecks.

For example, this minimal benchmark with one variable and a few control structures:

    x=0
    for i in range(int(10e6)):
        if i<50: x=x+1
    print (x)
Runs 5 times slower here than the same in PHP:

    $x=0;
    for ($i=0; $i<10e6; $i++)
        if ($i<50) $x++;
    echo "$x\n";
Tested with:

    time python3 loop.py
Which gives me 0.31s

And:

    time php loop.php
Which gives me 0.06s

A factor of five seems to be roughly the average when comparing Python to PHP for a bunch of different code constructs I tried.

Re:Python consumes 38x more energy than Java by snicker7 on Thursday July 13, 2023 @07:22AM (#36707518)
You can’t use time command in this sort of benchmark. You are including start up t times here.
Re:Python consumes 38x more energy than Java by mg on Thursday July 13, 2023 @07:24AM (#36707536)
Startup times seem to be the same and also negligible:

    time python3 nothing.py
    0.011s

    time php nothing.php
    0.011s
Re:Python consumes 38x more energy than Java by d-k-bo on Thursday July 13, 2023 @08:33AM (#36708174)
Startup time in Python depends on the program because Python compiles all modules to bytecode before executing them.
Re:Python consumes 38x more energy than Java by mg on Thursday July 13, 2023 @08:40AM (#36708245)
When I up the loop size by a factor of 10, Python takes 10x longer. So I don't think the compile time plays a role here.

Similar for the PHP version.

    python3 loop.py
    3.450s

    time php loop.php
    0.469s
So PHP is 7x faster for the longer loop.
Re:Python consumes 38x more energy than Java by igouy on Thursday July 13, 2023 @01:42PM (#36713081)
PHP JIT ?