Skip to content
/ cythonTemplate Public template

Personal template for a generic cython project setup

License

Notifications You must be signed in to change notification settings

djanloo/cythonTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cythonTemplate

Personal template for a generic cython project setup

  • Activate environment (pipenv shell)
  • Run make or possibly (hehe) import setup in the code to rebuild the package

Benchmark

The benchmark problem is counting the number of primes up to a certain value. Trivial algorithm chosen:

  • First three stop at n
  • Last three (r) stop at sqrt(n)

This allows to compare the sqrt evaluation (C vs Python).

Parallel computing using openMP is tested too, releasing the GIL and multithreading.

Results

O(n^2) functions

Just for declaring types and changing from range to prange we get:

  • Serial: x12
  • Parallel: x24

O(n^3/2) functions

Using libc.math:

  • Serial: x900
  • Parallel: x1700

Screenshot from 2022-09-01 16-00-16

Overall boost: 3000x

Profiling

Profiling slows down the code, so the compiler is not automatically set in profiler mode.

When needed, rebuild the package using

make profile

An example of line profiling is given in profile.py.

Some bugs in line_profiler for cython, not all functions are profiled.

A workaround is to shift the missing functions at the top of the code.

Other compiling modes

  • make hardcore: globally disables array wrapping, bound checks and enables cdivision
  • make force: forces compilation of already compiled extensions. Slows down the compilation if many .pyx files are found.

Screenshot from 2022-09-04 13-46-44

Screenshot from 2022-09-04 13-47-47

About

Personal template for a generic cython project setup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published