Python 3.6〜3.9のベンチマーク

Python 3.7がリリースされていたので、Benchmarkerのサンプルコードで簡単にベンチマークした結果です。

- https://pypi.org/project/Benchmarker/4.0.1/

# ベンチマーク結果

## 3.6

```bash
$ python3 example.py -o result3_6.json
## benchmarker:         release 4.0.1 (for python)
## python version:      3.6.5
## python compiler:     GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)
## python platform:     Darwin-16.7.0-x86_64-i386-64bit
## python executable:   /usr/local/opt/python/bin/python3.6
## cpu model:           Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
## parameters:          loop=1000000, cycle=1, extra=0

##                        real    (total    = user    + sys)
(Empty)                 0.0277    0.0300    0.0300    0.0000
join                    0.2340    0.2300    0.2300    0.0000
concat                  0.2714    0.2700    0.2700    0.0000
format                  0.3307    0.3200    0.3200    0.0000

## Ranking                real
join                    0.2340  (100.0) ********************
concat                  0.2714  ( 86.2) *****************
format                  0.3307  ( 70.8) **************

## Matrix                 real    [01]    [02]    [03]
[01] join               0.2340   100.0   116.0   141.3
[02] concat             0.2714    86.2   100.0   121.9
[03] format             0.3307    70.8    82.0   100.0
```

## 3.7

```bash
$ python3 example.py -o result3_7.json
## benchmarker:         release 4.0.1 (for python)
## python version:      3.7.0
## python compiler:     Clang 9.0.0 (clang-900.0.39.2)
## python platform:     Darwin-16.7.0-x86_64-i386-64bit
## python executable:   /usr/local/opt/python/bin/python3.7
## cpu model:           Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
## parameters:          loop=1000000, cycle=1, extra=0

##                        real    (total    = user    + sys)
(Empty)                 0.0258    0.0200    0.0200    0.0000
join                    0.2265    0.2400    0.2300    0.0100
concat                  0.3118    0.3200    0.3200    0.0000
format                  0.3388    0.3400    0.3400    0.0000

## Ranking                real
join                    0.2265  (100.0) ********************
concat                  0.3118  ( 72.7) ***************
format                  0.3388  ( 66.9) *************

## Matrix                 real    [01]    [02]    [03]
[01] join               0.2265   100.0   137.6   149.6
[02] concat             0.3118    72.7   100.0   108.7
[03] format             0.3388    66.9    92.0   100.0
```

# 所感

文字列結合がそこそこ遅くなっているのが目立つ。


# 3.8も出たので計測

計測マシンは変わってしまったので、参考値としてですが同様に計測しました。

```bash
$ python3.8 example.py -o result3_8.json
## benchmarker:         release 4.0.1 (for python)
## python version:      3.8.4
## python compiler:     Clang 11.0.3 (clang-1103.0.32.62)
## python platform:     macOS-10.15.5-x86_64-i386-64bit
## python executable:   /usr/local/opt/python@3.8/bin/python3.8
## cpu model:           Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
## parameters:          loop=1000000, cycle=1, extra=0

##                        real    (total    = user    + sys)
(Empty)                 0.0250    0.0200    0.0200    0.0000
join                    0.2017    0.2100    0.2100    0.0000
concat                  0.2530    0.2600    0.2600    0.0000
format                  0.3028    0.3000    0.3000    0.0000

## Ranking                real
join                    0.2017  (100.0) ********************
concat                  0.2530  ( 79.7) ****************
format                  0.3028  ( 66.6) *************

## Matrix                 real    [01]    [02]    [03]
[01] join               0.2017   100.0   125.5   150.1
[02] concat             0.2530    79.7   100.0   119.7
[03] format             0.3028    66.6    83.6   100.0
```

# 3.9も出たので計測

3.8と同じマシンで計測しました。

```bash
$ python3.9 example.py -o result3_9.json
## benchmarker:         release 4.0.1 (for python)
## python version:      3.9.0
## python compiler:     Clang 11.0.3 (clang-1103.0.32.62)
## python platform:     macOS-10.15.7-x86_64-i386-64bit
## python executable:   /usr/local/opt/python@3.9/bin/python3.9
## cpu model:           Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
## parameters:          loop=1000000, cycle=1, extra=0

##                        real    (total    = user    + sys)
(Empty)                 0.0243    0.0200    0.0200    0.0000
join                    0.2200    0.2300    0.2300    0.0000
concat                  0.2766    0.2700    0.2700    0.0000
format                  0.3161    0.3200    0.3200    0.0000

## Ranking                real
join                    0.2200  (100.0) ********************
concat                  0.2766  ( 79.5) ****************
format                  0.3161  ( 69.6) **************

## Matrix                 real    [01]    [02]    [03]
[01] join               0.2200   100.0   125.7   143.7
[02] concat             0.2766    79.5   100.0   114.3
[03] format             0.3161    69.6    87.5   100.0
```

3.8よりは遅くなっている感じ。