Mastering Python High Performance

Measure, optimize, and improve the performance of your Python code with this easy-to-follow guide

Mastering Python High Performance

Mastering
Fernando Doglio

Measure, optimize, and improve the performance of your Python code with this easy-to-follow guide
$31.99
$39.99
RRP $31.99
RRP $39.99
eBook
Print + eBook
$12.99 p/month

Get Access

Get Unlimited Access to every Packt eBook and Video course

Enjoy full and instant access to over 3000 books and videos โ€“ youโ€™ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

+ Collection
Free Sample

Book Details

ISBN 139781783989300
Paperback260 pages

About This Book

  • Master the do's and don'ts of Python performance programming
  • Learn how to use exiting new tools that will help you improve your scripts
  • A step-by-step, conceptual guide to teach you how to optimize and fine-tune your critical pieces of code

Who This Book Is For

If you're a Python developer looking to improve the speed of your scripts or simply wanting to take your skills to the next level, then this book is perfect for you.

Table of Contents

Chapter 1: Profiling 101
What is profiling?
The importance of profiling
What can we profile?
Memory consumption and memory leaks
The risk of premature optimization
Running time complexity
Profiling best practices
Summary
Chapter 2: The Profilers
Getting to know our new best friends: the profilers
line_profiler
Summary
Chapter 3: Going Visual โ€“ GUIs to Help Understand Profiler Output
KCacheGrind โ€“ pyprof2calltree
RunSnakeRun
Summary
Chapter 4: Optimize Everything
Memoization / lookup tables
Usage of default arguments
List comprehension and generators
ctypes
String concatenation
Other tips and tricks
Summary
Chapter 5: Multithreading versus Multiprocessing
Parallelism versus concurrency
Summary
Chapter 6: Generic Optimization Options
PyPy
Cython
How to choose the right option
Summary
Chapter 7: Lightning Fast Number Crunching with Numba, Parakeet, and pandas
Numba
The pandas tool
Parakeet
Summary
Chapter 8: Putting It All into Practice
The problem to solve
The initial code base
Summary

What You Will Learn

  • Master code optimization step-by-step and learn how to use different tools
  • Understand what a profiler is and how to read its output
  • Interpret visual output from profiling tools and improve the performance of your script
  • Use Cython to create fast applications using Python and C
  • Take advantage of PyPy to improve performance of Python code
  • Optimize number-crunching code with NumPy, Numba, Parakeet, and Pandas

In Detail

Simply knowing how to code is not enough; on mission-critical pieces of code, every bit of memory and every CPU cycle counts, and knowing how to squish every bit of processing power out of your code is a crucial and sought-after skill. Nowadays, Python is used for many scientific projects, and sometimes the calculations done in those projects require some serious fine-tuning. Profilers are tools designed to help you measure the performance of your code and help you during the optimization process, so knowing how to use them and read their output is very handy.

This book starts from the basics and progressively moves on to more advanced topics. Youโ€™ll learn everything from profiling all the way up to writing a real-life application and applying a full set of tools designed to improve it in different ways. In the middle, youโ€™ll stop to learn about the major profilers used in Python and about some graphic tools to help you make sense of their output. Youโ€™ll then move from generic optimization techniques onto Python-specific ones, going over the main constructs of the language that will help you improve your speed without much of a change. Finally, the book covers some number-crunching-specific libraries and how to use them properly to get the best speed out of them.

After reading this book, you will know how to take any Python code, profile it, find out where the bottlenecks are, and apply different techniques to remove them.

Authors

Table of Contents

Chapter 1: Profiling 101
What is profiling?
The importance of profiling
What can we profile?
Memory consumption and memory leaks
The risk of premature optimization
Running time complexity
Profiling best practices
Summary
Chapter 2: The Profilers
Getting to know our new best friends: the profilers
line_profiler
Summary
Chapter 3: Going Visual โ€“ GUIs to Help Understand Profiler Output
KCacheGrind โ€“ pyprof2calltree
RunSnakeRun
Summary
Chapter 4: Optimize Everything
Memoization / lookup tables
Usage of default arguments
List comprehension and generators
ctypes
String concatenation
Other tips and tricks
Summary
Chapter 5: Multithreading versus Multiprocessing
Parallelism versus concurrency
Summary
Chapter 6: Generic Optimization Options
PyPy
Cython
How to choose the right option
Summary
Chapter 7: Lightning Fast Number Crunching with Numba, Parakeet, and pandas
Numba
The pandas tool
Parakeet
Summary
Chapter 8: Putting It All into Practice
The problem to solve
The initial code base
Summary

Book Details

ISBN 139781783989300
Paperback260 pages
Read More

Recommended for You