Tricks to Optimise Numerical Code

Kousik Krishnan (~kousik)




Data is the new oil. With data proliferating from all sides, processing them becomes computationally intensive. Python, being the preferred language for easy prototyping, provides a powerful tool to handle these intensive tasks. But most often, the simplest analysis turns out to be painstakingly slow. This is because of the innate behaviour of the language and bad coding practices by developers. When used effectively though, Python can be as fast as other languages like C.

By analyzing different scenarios during which python underperforms, a formal rule-driven approach has been developed which can serve as golden principles for optimizing compute-intensive codes. In this talk, we will illustrate this approach using a simple algorithm and quantitatively measure its success using the total execution time as the performance metric.

Basic Outline of the talk

  • Python and its performance issue [3-5 minutes]
    • Speed - Analysis and understanding of slow execution time
  • Identifying scope for improvement [15-20 minutes]
    • What/When to optimize through code profiling
    • Scenario-based identification of appropriate data structures
    • Vectorisation using NumPy
    • Memory management - Knowhow of static typing in python
    • Data parallelism for scalability
  • Overall framework presentation [2-3 minutes]
    • Demo of example code with the applied principles
  • Q/A [2 minutes]

Who is this talk for?

  • Pythonistas who frequently hunt for performance optimization tricks.

  • Developers looking to switch to Python for handling computationally intensive tasks



  • Experience in handling computationally intensive codes.
  • Basics of data-structures (tree, heaps, hashmap, etc.)


  • Experience with vectorisation using numpy
  • Basic understanding of static vs dynamic typing

Beginners who do not have the recommended pre-requisites will be able to comprehend but not fully appreciate the content.

Video URL:

Content URLs:

The presentation which is currently in development can be viewed here.

A short video pitch of the talk is available here.

All the codes will be made available by the latest.

Speaker Info:

Kousik is a Quant Analyst working in the financial services industry where he is responsible for developing quantitative models for financial prediction and risk management. He primarily uses Python and C++ for dealing with number crunching tasks and is constantly in lookout for cool tricks to optimize code. In his college days, he successfully helped develop a high performance risk management framework for an alternate investment fund which was validated and approved by SEBI. He was also involved in different technical talks at IIT-M, conferences like PySangamam and is a member of the Chennai Python Meetup group. His love for python started 5 years ago, with a multitude of quant finance and machine learning projects.

Section: Scientific Computing
Type: Talks
Target Audience: Intermediate
Last Updated: