Python High Performance Programming


Python High Performance Programming
eBook: $17.99
Formats: PDF, PacktLib, ePub and Mobi formats
$15.29
save 15%!
Print + free eBook + free PacktLib access to the book: $47.98    Print cover: $29.99
$29.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Identify the bottlenecks in your applications and solve them using the best profiling techniques
  • Write efficient numerical code in NumPy and Cython
  • Adapt your programs to run on multiple processors with parallel programming

Book Details

Language : English
Paperback : 108 pages [ 235mm x 191mm ]
Release Date : December 2013
ISBN : 1783288450
ISBN 13 : 9781783288458
Author(s) : Gabriele Lanaro
Topics and Technologies : All Books, Open Source


Table of Contents

Preface
Chapter 1: Benchmarking and Profiling
Chapter 2: Fast Array Operations with NumPy
Chapter 3: C Performance with Cython
Chapter 4: Parallel Processing
Index
  • Chapter 1: Benchmarking and Profiling
    • Designing your application
    • Writing tests and benchmarks
      • Timing your benchmark
    • Finding bottlenecks with cProfile
    • Profile line by line with line_profiler
    • Optimizing our code
    • The dis module
    • Profiling memory usage with memory_profiler
    • Performance tuning tips for pure Python code
    • Summary
  • Chapter 2: Fast Array Operations with NumPy
    • Getting started with NumPy
      • Creating arrays
      • Accessing arrays
      • Broadcasting
      • Mathematical operations
      • Calculating the Norm
    • Rewriting the particle simulator in NumPy
    • Reaching optimal performance with numexpr
    • Summary
  • Chapter 3: C Performance with Cython
    • Compiling Cython extensions
    • Adding static types
      • Variables
      • Functions
      • Classes
    • Sharing declarations
    • Working with arrays
      • C arrays and pointers
      • NumPy arrays
      • Typed memoryviews
    • Particle simulator in Cython
    • Profiling Cython
    • Summary
  • Chapter 4: Parallel Processing
    • Introduction to parallel programming
    • The multiprocessing module
      • The Process and Pool classes
      • Monte Carlo approximation of pi
      • Synchronization and locks
    • IPython parallel
      • Direct interface
      • Task-based interface
    • Parallel Cython with OpenMP
    • Summary

Gabriele Lanaro

Gabriele Lanaro is a PhD student in Chemistry at the University of British Columbia, in the field of Molecular Simulation. He writes high performance Python code to analyze chemical systems in large-scale simulations. He is the creator of Chemlab—a high performance visualization software in Python—and emacs-for-python—a collection of emacs extensions that facilitate working with Python code in the emacs text editor. This book builds on his experience in writing scientific Python code for his research and personal projects.

Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 5 submitted: last submission 25 Feb 2014

Errata type: Grammar | Page number: 81

When a process acquires a lock, other processes are prevented to acquire it until the lock is released.

should be:

When a process acquires a lock, other processes are prevented from acquiring it until the lock is released.

Errata type: Technical | Page number: 39

Broadcast figure for "b1", top row, should be:

b1 b1 b1

not:

b1 b2 b2

Errata type: Code | Page number: 36

 

In [35]: a = np.array([[0, 1, 2], [3, 4, 5],
                              [6, 7, 8], [9, 10, 11]])
In [36]: idx1 = np.array([0, 1])
In [37]: idx2 = np.array([2, 3])
In [38]: a[idx1, idx2]

should be:

In [35]: a = np.array([[0, 1, 2], [3, 4, 5],

                                  [6, 7, 8], [9, 10, 11]])

In [36]: idx1 = np.array([0, 3])

In [37]: idx2 = np.array([2, 1])

In [38]: a[idx1, idx2]

Out[15]: array([ 2, 10])

 

 

Errata Type: Grammar | Errata Page: 21

For example, taylor_expcalls <listcomp> (a 

list comprehension) which calls factorial 500 times taylor_sin calls factorial 250

times. KCachegrind also detects recursive calls: factorial calls itself 187250 times.

should be:

For example, taylor_expcalls <listcomp> (a 

list comprehension) which calls factorial 500 times. taylor_sin calls factorial 250

times. KCachegrind also detects recursive calls: factorial calls itself 187250 times.

Errata type: Grammar | Page No: 14

Our test will take three particle and let the system evolve for 0.1 time units.

should be:

Our test will take three particles and let the system evolve for 0.1 time units.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Python High Performance Programming +    PrimeFaces Cookbook =
50% Off
the second eBook
Price for both: $31.94

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Assess the performance of your programs using benchmarks
  • Spot the bottlenecks in your code using the Python profiling tools
  • Speed up your code by replacing Python loops with NumPy
  • Boost NumPy performance using the numexpr compiler
  • Use Cython to reach performance on par with the C language
  • Write code for multiple processors
  • Profile, optimize, and rewrite an application from start to finish

In Detail

Python is a programming language with a vibrant community known for its simplicity, code readability, and expressiveness. The massive selection of third party libraries make it suitable for a wide range of applications. This also allows programmers to express concepts in fewer lines of code than would be possible in similar languages. The availability of high quality numerically-focused tools has made Python an excellent choice for high performance computing. The speed of applications comes down to how well the code is written. Poorly written code means poorly performing applications, which means unsatisfied customers.

This book is an example-oriented guide to the techniques used to dramatically improve the performance of your Python programs. It will teach optimization techniques by using pure python tricks, high performance libraries, and the python-C integration. The book will also include a section on how to write and run parallel code.

This book will teach you how to take any program and make it run much faster. You will learn state-of the art techniques by applying them to practical examples. This book will also guide you through different profiling tools which will help you identify performance issues in your program. You will learn how to speed up your numerical code using NumPy and Cython. The book will also introduce you to parallel programming so you can take advantage of modern multi-core processors.

This is the perfect guide to help you achieve the best possible performance in your Python applications.

Approach

An exciting, easy-to-follow guide illustrating the techniques to boost the performance of Python code, and their applications with plenty of hands-on examples.

Who this book is for

If you are a programmer who likes the power and simplicity of Python and would like to use this language for performance-critical applications, this book is ideal for you. All that is required is a basic knowledge of the Python programming language. The book will cover basic and advanced topics so will be great for you whether you are a new or a seasoned Python developer.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software