Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fast Python, Slow Python by Alex Gaynor

Fast Python, Slow Python by Alex Gaynor

PyCon 2014

April 12, 2014
Tweet

More Decks by PyCon 2014

Other Decks in Programming

Transcript

  1. About me • Core developer of Django, PyPy, CPython, etc.

    • Director of the Python Software Foundation • Work at Rackspace (Thanks!)
  2. if (! (hex is None) + (bytes is None) +

    (bytes_le is None) +! (fields is None) + (int is None)! ) != 4:! raise TypeError!
  3. char *data = malloc(1025);! while (true) {! size_t n =

    read(fd, data, 1024);! data[n] = '\0';! char *start = data;! while (start < data + n) {! if (isspace(*start)) {! break;! }! start++;! }! printf("%s\n", start);! }!
  4. from zero_buffer import Buffer! ! b = Buffer.allocate(8192)! with open(path,

    "rb") as f:! b.read_from(f.fileno())! for part in b.view().split(b":"):! part.write_to(sys.stdout.fileno())! sys.stdout.write('\n')!
  5. A few more myths • Functions calls are really expensive

    • Using only builtin data types will make your code fast • Don’t write Python in the style of Java or C