Differences between revisions 1 and 2
Revision 1 as of 2006-09-30 03:40:47
Size: 1735
Editor: DavidHarvey
Comment: started page
Revision 2 as of 2006-10-01 00:03:42
Size: 1797
Editor: DavidHarvey
Comment:
Deletions are marked like this. Additions are marked like this.
Line 44: Line 44:

== "==" vs "is" ==

[ todo ]

 * e.g. testing for None

[ this page is under construction ]

Introduction

This page describes some techniques for writing really fast Pyrex code. It is aimed at SAGE developers who are working on low-level SAGE internals, where performance is absolutely crucial.

Pyrex is a very unusual language. If you write Pyrex as if it were Python, it can end up running as slowly as Python. If you write it like you're writing C, it can run almost as fast as pure C. The amazing thing about Pyrex is that the programmer gets to choose, pretty much line by line, where along the Python-C spectrum they want to work.

HOWEVER... it is hard work to make your Pyrex as fast as C. It's very easy to get it wrong, essentially because Pyrex makes it all look so easy. This purpose of this document is to collect together the experiences of SAGE developers who have learned the hard way.

How to contribute to this document

Yes, please do! Make sure to follow these guidelines:

  • When you give an example, make sure to constrast a fast way of doing things with a slow way, especially if the slow way is more obvious. Show both versions of the Pyrex code, and show the generated C code as well (if you think that this is useful to see).

  • Let's keep this scientific: show some evidence of performance (e.g. timing data).

Examples

cdef functions vs def functions

[ todo ]

  • function call overhead -- constructing tuples
  • parseTuple stuff inside the def function

python attributes vs cdef attributes

[ todo ]

avoid python name lookups

[ todo ]

type checking

[ todo ]

"==" vs "is"

[ todo ]

  • e.g. testing for None