0

I am using cython to improve the performance of the python functions. Basically i can improve performance only in dictionary operations. So i was trying to search for any dictionary written in c, I found that cython itself contains a .pxd file which is basically wrapper for .h file at "Cython/includes/cpython". My question is if i directly use cimport dict,how to include the above mentioned path while compiling?

If i use this dict.pxd will i get any improvement in performance ? I attached the code from dict.pxd

https://github.com/cython/cython/blob/master/Cython/Includes/cpython/dict.pxd

srujith poondla
  • 171
  • 1
  • 12
  • 2
    The regular Python dict type is already written in C. The file you found simply declares the Python C API functions for working with dicts; using them explicitly probably won't help if your variable types are declared properly. – user2357112 Jun 28 '17 at 17:37
  • 1
    The Python dictionary is already a highly optimized hashmap implementation. You will likely see worse performance than before. https://stackoverflow.com/q/29268914/4131059 – Alex Huszagh Jun 28 '17 at 17:38
  • In my experience I have managed to significantly speed up `list` initialisation code by using the equivalent file and the functions directly. I don't think the `dict` C API is as useful though. Also, to answer part of the question, if you do `cimport dict` the header will be automatically included. – DavidW Jun 28 '17 at 19:05
  • @DavidW If I do `cimport dict` it is throwing an error during compilation. Could you please explain a bit more, how you used list.pxd from includes directory. – srujith poondla Jun 28 '17 at 19:30
  • You do `cimport cpython.dict` (or `from cpython cimport dict`) – DavidW Jun 28 '17 at 19:35
  • Thanks @DavidW it's working!! – srujith poondla Jun 28 '17 at 19:55

0 Answers0