3

Is there something equivalent to Cython for IronPython? That is, a way to compile simple functions using type annotations to increase performance? I know one of the benefits of IronPython is the ability to quickly write functions in something like C# or F# and then import them, but this can be somewhat of a burden for users who are only familiar with Python.

Tristan
  • 6,776
  • 5
  • 40
  • 63

1 Answers1

0

Hmm .. IronPython is already way faster than good ol' CPython :)

Having said that, you can create binaries from source with pyc (look in <IronPython 2.6 Install Dir>\Tools\Scripts\pyc.py).

It looks like there are a number of output options, including making a dll. I presume it is possible to import a dll like that from a regular .py program (I've never tried this though).

I really don't know if this is going to increase performance beyond what you already get with IronPython though (it probably improves startup time).


Update:

I just did a bit of testing, and converting to exe gives me a really marginal 3-5% speed improvement, and doesn't help startup time. It seemed like a good idea :|

Community
  • 1
  • 1
Seth
  • 45,033
  • 10
  • 85
  • 120
  • 4
    I'm not talking about CPython, I'm talking about Cython. Cython is compiled C translated from Pythonesque code. This can lead to 500x increase in speed over CPython or Ironpython for numeric code. Second, it simply isn't true that IronPython is way faster than CPython: it is competitive, sometimes slower, sometimes faster. The Richards benchmark on that page is twice as slow for instance. – Tristan Jan 12 '10 at 22:40
  • Sorry, I re-read my answer and can see how it would be a bit confusing. My point was that IronPython is already compiled into machine code dynamically; if you convert to EXE, you'll get a DLR binary image which will by automatically compiled into machine code. I can't imagine that you can get any faster than that (maybe writing a DLL in C# and calling into that would be faster, but then you'd be writing C#). Also - In my experience (with my programs), IronPython is faster than CPython if you exclude startup time (which is a lot to exclude). – Seth Jan 12 '10 at 23:26
  • If you want to improve startup time, you should AOT IronPython libraries. – konrad.kruczynski Jan 26 '12 at 20:52
  • @konrad: what is "AOT", please avoid such nebulous acronyms – Oliver Jul 10 '13 at 14:27
  • @Schollii: http://www.mono-project.com/AOT .NET equivalent would be NGEN: http://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.110).aspx – konrad.kruczynski Jul 10 '13 at 14:52
  • @Seth the point is to get CLR code instead of DLR code. That is, to have variables with types that are STATICALLY known, so that the JIT can optimize accordingly. For example, if a variable is known to be holding a System.Integer32, and you add two such variables, the optimized code can be a single machine instruction. Avoiding whatever check the DLR code has to perform. (Though hopefully DLR is smart enough to pre-check variable types before a loop, and direct to optimal code inside a loop. If so, then maybe CLR vs DLR not such a big deal. Researching that topic now.) – ToolmakerSteve Dec 18 '13 at 18:45