LoginSignup
1
0

More than 3 years have passed since last update.

CPython vs PyPy vs Pyston

Last updated at Posted at 2020-11-24

はじめに

最近ネットでPyston2に関する記事を見かけるようになりました。
Pythonより20%高速、「Pyston 2.0」が登場

今まで聞いたことのないPython処理系だったのでインストールして他の処理系との速度比較を行ってみました。

以下の環境で実行しました。

Windows 10 Home 19041.630
Ubuntu-20.04 on WSL
Python 3.8.5 (公式、以下CPython)
Python 3.6.9 (PyPy 7.3.1)
Python 3.8.2 (Pyston 2.0.0)

Pystonは現在Ubuntuでしか利用できないためWSLを利用しました。

今回はそれぞれのインストール方法は割愛します。
それぞれのホームページなどを参考にしてインストールしてください。

プログラム

Pythonでtimetest.pyを実行し内部からそれぞれの処理系で_timetest.pyを呼び出し、subprocessを使って結果を取得しています。

# timetest.py

import subprocess

binaries = ["python3", "pypy3", "pyston"]

for binary in binaries:
    out = subprocess.check_output([binary, "./_timetest.py"])
    print(out.decode())

# _timetest.py

import time, sys

def main_func(number):
    big_array = []
    one_tenth = number // 10
    for i in range(10):
        big_array.append([])
        little_array = big_array[i]
        for j in range(one_tenth):
            data = i * one_tenth + j
            little_array.append(data)
    return big_array

def clock(number):
    start = time.time()
    _ = main_func(number)
    result = time.time() - start
    rounded = round(result, 3)
    return rounded

number = 40_000_000
version = sys.version

binary = "PyPy" if "PyPy" in version else "Pyston" if "Pyston" in version else "CPython"
result = clock(number)

print(f"{binary}\t{result}[sec]", end="")

実行結果

Pystonはどれくらい早いのかと楽しみにしていたんですが、
な、なんと、CPythonよりも遅いという結果になりました。

1位はPyPyでこれは予想道理でしたが、まさかPystonがCPythonよりも遅いという結果になるとは...

CPython PyPy Pyston
3.415[sec] 0.472[sec] 4.088[sec]

もちろんこのプログラムとの相性もあるとは思いますがとても残念です。

さいごに

残念な結果になってしまいましたが1位のPyPyは他のよりも7倍以上高速です。
もし今使うことになればマニュアルも豊富なPyPyですね。

まだ改善点は沢山あるようなのでこれからに期待したいです。

スターを付けてもらうと励みになります :relaxed:
読んでいただきありがとうございました。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0