4 ms·
I am using Python to solve combinatorial problems, and so my code relies heavily on the itertools library. My question is if I would still get a considerable s
by python_que 11y ago
I am using Python to solve combinatorial problems, and so my code relies heavily on the itertools library.
My question is if I would still get a considerable speed-up if I rewrite some of my code in Cython, given my reliance on itertools?
- dagw 11y agoThe calls to itertools won't be sped up significantly. However if then you loop over the results of a call to itertools and do something to each element, then that loop might end up being much faster.
- versteegen 11y agoAs dagw said, if your inner loops aren't inside a .pyx file, then Cython can do little to help. Even if there are, if it involves lots of fiddling with data structures like dicts and lists, or making use of dynamic or high level features of Python like generators or classes or list comprehensions, then Cython would provide only a small speed increase (say, 20%), because almost all the running time will be spent inside the Python runtime. To get the biggest speed ups out of Cython you need to write C-like code with type annotations. E.g. "for x in range(...):" loops.
- hogu 11y agoit may be worth checking out cytoolz
- mathnode 11y agoYup. Cytoolz. Some notes on performance of Cytoolz: http://matthewrocklin.com/blog/work/2014/05/01/Introducing-CyToolz/ http://matthewrocklin.com/blog/work/2014/05/01/Introducing-C...
- python_que 11y agogreat thanks both for the tip.