Author methane
Recipients Mark.Shannon, methane, nascheme, pablogsal, vstinner, yselivanov
Date 2020-10-22.09:37:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603359466.12.0.873875674403.issue42115@roundup.psfhosted.org>
In-reply-to
Content
FWIW, php7 is about 5x faster than Python on spectral norm benchmark.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/php-python3.html

There two major reasons:

* PHP uses scalar type for float and int
* PHP uses type-specialized bytecode (PHP8 will use JIT, but PHP7 dosn't)

Source code is here:
php: https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/spectralnorm-php-1.html
Python: https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/spectralnorm-python3-8.html

The most hot function is eval_A()

```
def eval_A(i, j): # i and j are int.
    ij = i + j
    return ij * (ij + 1) // 2 + i + 1
```

And its bytecode:

```
Disassembly of <code object eval_A at 0x107fd8500, file "x.py", line 1>:
  2           0 LOAD_FAST                0 (i)
              2 LOAD_FAST                1 (j)
              4 BINARY_ADD
              6 STORE_FAST               2 (ij)

  3           8 LOAD_FAST                2 (ij)
             10 LOAD_FAST                2 (ij)
             12 LOAD_CONST               1 (1)
             14 BINARY_ADD
             16 BINARY_MULTIPLY
             18 LOAD_CONST               2 (2)
             20 BINARY_FLOOR_DIVIDE
             22 LOAD_FAST                0 (i)
             24 BINARY_ADD
             26 LOAD_CONST               1 (1)
             28 BINARY_ADD
             30 RETURN_VALUE
```

My thoughts:

* bytecode specialized for `int op int` will some help.
* there are many incref/decref overhead.
  * multi operand bytecode (e.g. BINARY_ADD_FAST_FAST, BINARY_ADD_FAST_CONST, etc) will reduce refcount overhead.
History
Date User Action Args
2020-10-22 09:37:46methanesetrecipients: + methane, nascheme, vstinner, Mark.Shannon, yselivanov, pablogsal
2020-10-22 09:37:46methanesetmessageid: <1603359466.12.0.873875674403.issue42115@roundup.psfhosted.org>
2020-10-22 09:37:46methanelinkissue42115 messages
2020-10-22 09:37:45methanecreate