Last active
October 19, 2015 08:37
-
-
Save rokujyouhitoma/25c2ac037be795a374fc to your computer and use it in GitHub Desktop.
TinySegmenter.pyをPurePythonとCython(型情報なし、PurePythonコードをCythonでコンパイルしただけ)の速度比較
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TinySegmenter.pyを速度改善してみる。 | |
手抜きで、Cythonでコンパイルするだけでいいかなー。と。 | |
TinySegmenter.pyをPurePythonとCython(型情報なし、PurePythonコードをCythonでコンパイルしただけ)の速度比較した。 | |
結論Cythonでコンパイルするだけで速度改善できた。 | |
更に速度したいなら、 | |
1. Cythonで型情報を付与。 | |
2. Cに持ってく。 | |
3. PyPyもあり? | |
コミットはこれ。 | |
https://github.com/rokujyouhitoma/nltk/commit/f9eee1427070ae566994d5e690d622f19f2dad4f | |
# Cython版 | |
# https://github.com/rokujyouhitoma/nltk/blob/feature/cythonize/jpbook/cythonize_tinysegmenter/cythonize_tinysegmenter.py | |
In [1]: %timeit -n 100 %run cythonize_tinysegmenter.py | |
私 | の | 名前 | は | 中野 | です | |
: | |
私 | の | 名前 | は | 中野 | です | |
100 loops, best of 3: 570 µs per loop | |
# Pure Python版 | |
# https://github.com/rokujyouhitoma/nltk/blob/feature/cythonize/jpbook/tinysegmenter.py | |
In [2]: %timeit -n 100 %run tinysegmenter.py | |
私 | の | 名前 | は | 中野 | です | |
: | |
私 | の | 名前 | は | 中野 | です | |
100 loops, best of 3: 5.95 ms per loop | |
Ref: https://twitter.com/rokujyouhitoma/status/655925802614157316 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment