O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Python High Performance Programming

Book Description

If you have at least a basic knowledge of Python, this book will help you maximize the performance of your code and applications. Easy to follow tutorials will make you a hard act to follow in Python programming.

  • 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

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.

Table of Contents

  1. Python High Performance Programming
    1. Table of Contents
    2. Python High Performance Programming
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
      7. Downloading the example code
      8. Errata
      9. Piracy
      10. Questions
    8. 1. Benchmarking and Profiling
      1. Designing your application
      2. Writing tests and benchmarks
        1. Timing your benchmark
      3. Finding bottlenecks with cProfile
      4. Profile line by line with line_profiler
      5. Optimizing our code
      6. The dis module
      7. Profiling memory usage with memory_profiler
      8. Performance tuning tips for pure Python code
      9. Summary
    9. 2. Fast Array Operations with NumPy
      1. Getting started with NumPy
        1. Creating arrays
        2. Accessing arrays
        3. Broadcasting
        4. Mathematical operations
        5. Calculating the Norm
      2. Rewriting the particle simulator in NumPy
      3. Reaching optimal performance with numexpr
      4. Summary
    10. 3. C Performance with Cython
      1. Compiling Cython extensions
      2. Adding static types
        1. Variables
        2. Functions
        3. Classes
      3. Sharing declarations
      4. Working with arrays
        1. C arrays and pointers
        2. NumPy arrays
        3. Typed memoryviews
      5. Particle simulator in Cython
      6. Profiling Cython
      7. Summary
    11. 4. Parallel Processing
      1. Introduction to parallel programming
      2. The multiprocessing module
        1. The Process and Pool classes
        2. Monte Carlo approximation of pi
        3. Synchronization and locks
      3. IPython parallel
        1. Direct interface
        2. Task-based interface
      4. Parallel Cython with OpenMP
      5. Summary
    12. Index