There are several ways to profile a Python script:
Python code can run faster in a function because of something called "Just-In-Time" (JIT) compilation.