File tree Expand file tree Collapse file tree 6 files changed +38
-0
lines changed
Expand file tree Collapse file tree 6 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 44import itertools
55import myrustlib # <-- Importing Rust Implemented Library
66
7+ import sys
8+ sys .path .append ('./pyext-myclib' )
9+ import myclib # <-- Importing C Implemented Library
10+
711
812def count_doubles (val ):
913 total = 0
@@ -68,5 +72,9 @@ def test_rust_once(benchmark):
6872 print (benchmark (myrustlib .count_doubles_once , val ))
6973
7074
75+ def test_c_bytes_once (benchmark ):
76+ print (benchmark (myclib .count_byte_doubles , val ))
77+
78+
7179# def test_rust_regex(benchmark):
7280# print(benchmark(myrustlib.count_doubles_regex, val))
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ python3 setup.py build_ext -i
Original file line number Diff line number Diff line change 1+ #include "myclib.h"
2+
3+ uint64_t count_byte_doubles (char * str ) {
4+ uint64_t count = 0 ;
5+ while (str [0 ] && str [1 ]) {
6+ if (str [0 ] == str [1 ]) count ++ ;
7+ str ++ ;
8+ }
9+ return count ;
10+ }
Original file line number Diff line number Diff line change 1+ #include <stdint.h>
2+
3+ uint64_t count_byte_doubles (char * str );
Original file line number Diff line number Diff line change 1+ %module myclib
2+ %{
3+ #include " myclib.h"
4+ %}
5+
6+ %include " stdint.i"
7+ %include " myclib.h"
Original file line number Diff line number Diff line change 1+ from distutils .core import setup , Extension
2+
3+ setup (ext_modules = [
4+ Extension ('_myclib' ,
5+ sources = ['myclib.i' , 'myclib.c' ],
6+ depends = ['setup.py' , 'mylib.h' ]
7+ )
8+ ])
You can’t perform that action at this time.
0 commit comments