Optimizing slow Python functions in large codebases is a nightmare. You can try Numba or Cython, but Numba mainly works only with numerical code and NumPy arrays.
You could go with Cython, but that requires .pyx files, type annotations, and compilation. In reality, it's hours of refactoring before you even see any improvement. 😬
Codon solves this with just one line: the codon.jit decorator compiles your Python directly into machine code.
Key advantages:
• Works with any Python code, not just NumPy
• No need for type annotations - types are inferred automatically
• Compiled functions are cached and called instantly
• No code changes required except adding the decorator
Here are real performance measurements:
• Pure Python: 0.240 s
• First Codon call: 0.324 s (one-time compilation)
• Repeated Codon calls: 0.006 s (37x speedup)
Link to GitHub, Run this code
••••••••••••••••
🤖 Data Science, ML & Big Data with @DataXplore
