Skip to content

mfkiwl/faster-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

faster-python

Rust is so fast, and python can leverage power of rust.

By the way, you know, python is too slow ??

This is not what proves that rust is better than cpp. Apparently, cpp(nanobind) is able to become even faster. [link]

Usage

$ git clone <repo> && cd <repo>
$ poetry install
$ poetry shell
$ cmake -S . -B build
$ cmake --build build

#############
# benchmark #
#############
$ python main.py --fibonacci 40

python                : 21.961166224995395
python(numba)         : 0.7921977119985968
python(numba-nopython): 0.7205598769942299
python(cython)        : 0.6859547469939571
c++(nanobind)         : 0.3306063709896989
rust(pyo3)            : 0.21601284098869655

How to make each of python bindings

  • nanobind
    • $ pip install nanobind
    • edit CMakeLists.txt
    • edit <file_name>.cpp
    • $ cmake -S . -B build
    • $ cmake --build build
  • pyo3
    • $ pip install maturin
    • $ maturin new -b pyo3 rusty-python
    • $ cd rusty-python
    • edit src/lib.rs
    • and back to base directory of poetry
    • $ pip install ./rusty-python/

Other ways to make python faster

First of all, you need to identify bottlenecks using either of ways which cProfile, time.perfcounter(), %%timeit.

  • improve time-complexity in terms of Big O Notation
  • use multi thread or process
  • use numpy?
  • use PyPy
  • use codon?

Reference

About

python project benchmark using python, numba, cython, nanobind(c++), pyo(rust)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors