File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55/pyext-myclib /myclib.py
66/pyext-myclib /myclib_wrap.c
77/pyext-myclib /_myclib.cpython *
8+ /pyext-mycythonlib /* .so
9+ /pyext-mycythonlib /* .c
10+ /pyext-mycythonlib /* .html
811.cache
912.benchmarks
1013__pycache__
1114myrustlib.so
15+ mycythonlib * .so
1216/pyext-myrustlib /.gitignore
Original file line number Diff line number Diff line change 1- .PHONY : clean clean-test clean-pyc clean-build docs help
1+ .PHONY : clean clean-test clean-pyc clean-build docs help test-python test-rust test-c test-cython compile-cython compile-rust compile-c
22
33clean : clean-build clean-pyc clean-test # # remove all build, test, coverage and Python artifacts
44
55clean-build : # # remove build artifacts
66 rm -fr build/
77 rm -fr dist/
88 rm -fr .eggs/
9+ rm -fr .compiled
910 find . -name ' *.egg-info' -exec rm -fr {} +
1011 find . -name ' *.egg' -exec rm -f {} +
1112
@@ -32,6 +33,9 @@ test-rust: ## run tests quickly with the default Python
3233test-c : # # run tests quickly with the default Python
3334 py.test -v -s doubles_with_c_swig.py
3435
36+ test-cython : # run tests quickly with the default Python
37+ py.test -v -s doubles_with_cython.py
38+
3539test-all : # # run tests quickly with the default Python
3640 py.test -v -s doubles_all.py
3741
@@ -41,3 +45,14 @@ compile-rust: ## compile new rust lib
4145
4246compile-c : # # compile new c lib
4347 @cd pyext-myclib; python3 setup.py build_ext -i
48+
49+ compile-cython : # # compile new cython lib
50+ @cd pyext-mycythonlib; cythonize -a -i mycythonlib.pyx
51+ @cp pyext-mycythonlib/mycythonlib* .so ./
52+
53+ compile-all : compile-rust compile-c compile-cython
54+
55+ .compiled : compile-all
56+ touch .compiled
57+
58+ test : compile-all test-all
Original file line number Diff line number Diff line change 44import itertools
55import numpy as np
66import myrustlib # <-- Importing Rust Implemented Library
7+ import mycythonlib # <-- Importing Cython Implemented Library
78
89import sys
910sys .path .append ('./pyext-myclib' )
@@ -101,3 +102,6 @@ def test_c_swig_bytes_once(benchmark):
101102
102103# def test_rust_regex(benchmark):
103104# print(benchmark(myrustlib.count_doubles_regex, val))
105+
106+ def test_cython (benchmark ):
107+ print (benchmark (mycythonlib .count_doubles , val ))
Original file line number Diff line number Diff line change 1+ def count_doubles ( unicode source ):
2+ """ Count number of doubles in a (unicode) string
3+
4+ A double is counted for every character where the
5+ character at the previous index in the string is
6+ the same character as the current character. Thus
7+ the string 'aaa' has two doubles.
8+ """
9+ cdef Py_ssize_t count
10+ count = 0
11+ if not source:
12+ return count
13+ char = source[0 ]
14+ for next_char in source[1 :]:
15+ if next_char == char :
16+ count += 1
17+ char = next_char
18+ return count
Original file line number Diff line number Diff line change 11pytest
22pytest-benchmark
33numpy
4+ cython
You can’t perform that action at this time.
0 commit comments