Skip to content

Instantly share code, notes, and snippets.

@rokujyouhitoma
Last active October 19, 2015 08:37
Show Gist options
  • Save rokujyouhitoma/25c2ac037be795a374fc to your computer and use it in GitHub Desktop.
Save rokujyouhitoma/25c2ac037be795a374fc to your computer and use it in GitHub Desktop.
TinySegmenter.pyをPurePythonとCython(型情報なし、PurePythonコードをCythonでコンパイルしただけ)の速度比較
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