Measure Python code performance with cProfile and line_profiler, and apply practical optimisation techniques