問題描述
是否可以將 Python 程序轉(zhuǎn)換為 C/C++?
is it possible to convert a Python program to C/C++?
我需要實現(xiàn)幾個算法,我不確定性能差距是否足以證明我在 C/C++ 中執(zhí)行它時所經(jīng)歷的所有痛苦(我不擅長)).我想寫一個簡單的算法,并根據(jù)這樣一個轉(zhuǎn)換后的解決方案對其進(jìn)行基準(zhǔn)測試.如果僅此一項就比 Python 版本快得多,那么我將別無選擇,只能用 C/C++ 來實現(xiàn).
I need to implement a couple of algorithms, and I'm not sure if the performance gap is big enough to justify all the pain I'd go through when doing it in C/C++ (which I'm not good at). I thought about writing one simple algorithm and benchmark it against such a converted solution. If that alone is significantly faster than the Python version, then I'll have no other choice than doing it in C/C++.
推薦答案
是的.查看 Cython.它就是這樣做的:將 Python 轉(zhuǎn)換為 C 以提高速度.
Yes. Look at Cython. It does just that: Converts Python to C for speedups.
這篇關(guān)于將 Python 程序轉(zhuǎn)換為 C/C++ 代碼?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!