Skip to content

worldveil/cython-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cython-example

Quick example of cythonizing a function. Shouldn't be taken as a model implementation - just for my own reference.

Example taken from the official Cython tutorial.

Coding

Everything needed is in primes.pyx.

The corresponding pure Python function is located in primes_py.py.

Running

There are two ways to run.

  1. Compiling automatically using pyximport
  2. Manually building the extension

Compiling automatically

Simply run:

$ python test_quick.py
Pure Python version average 0.9142 +/- 0.04769 seconds
Cython version average 0.0276 +/- 0.00300 seconds

Cython speed up: 33.120

Compile into an extension

$ sh setup.sh
$ python test.py
Cython version average 1.0102 +/- 0.08426 seconds
Cython version average 0.0271 +/- 0.00164 seconds

Cython speed up: 37.217

Cleaning up

$ sh reset.sh

About

Example Cython extension creation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published