| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
FastMath Utilities is a lightweight Python module that provides fast-path wrappers around commonly used mathematical operations, constants, and performance-oriented patterns. The goal is not to replace Python’s standard library, but to expose performance-friendly access patterns that reduce overhead in tight loops, hot paths, and numerical workloads.
This module focuses on:
It is designed for Python 3.10+ and works especially well in performance-sensitive code.
Python performance is often limited not by computation itself, but by overhead:
FastMath Utilities removes these costs by:
There is no hidden magic here. The speed comes from removing friction.
This module can be vendored directly into a project or packaged as part of a larger performance-focused library.
pip install fasterPythonIf copied directly into your codebase, no installation step is required.
Thin wrappers around math functions with minimal overhead.
fast_sqrt(x)
fast_ceil(x)
fast_floor(x)
fast_factorial(x)
fast_log(x, base=None)
fast_exp(x)
fast_sin(x)Example:
from fasterPython.fasterPython import fast_sqrt, fast_log
fast_sqrt(25) # 5.0
fast_log(8, 2) # 3.0
fast_log(10) # natural logarithmConstants are exposed directly to avoid function call overhead.
FAST_PI
FAST_E
FAST_TAU
FAST_INF
FAST_NANExample:
from fasterPython.fasterPython import FAST_PI
area = FAST_PI * r * rA cached recursive Fibonacci implementation using functools.lru_cache.
fib(n)Example:
from fastmath import fib
fib(40) # computed once and reusedThis avoids the exponential blow-up of naive recursion and is suitable for repeated calls.
A hand-rolled summation loop that avoids function call overhead and shadowing built-ins.
sum_fast(iterable)Example:
from fastmath import sum_fast
sum_fast([1, 2, 3, 4])This is ideal for small to medium iterables where NumPy would introduce unnecessary overhead.
Efficient square computation using local method binding to reduce attribute lookup cost.
compute_squares(nums)Example:
from fastmath import compute_squares
compute_squares([1, 2, 3, 4])If NumPy is installed, a fast vectorized summation function is available.
sum_numpy(nums)Example:
from fasterPython.fasterPython import sum_numpy
sum_numpy(range(1_000_000))If NumPy is not installed, calling this function raises a clear runtime error instead of failing silently.
FastMath Utilities is useful when:
It is not intended to replace NumPy, SciPy, or compiled extensions for large-scale numerical workloads.
Benchmarks were run on Python 3.12, Windows 11, x86-64 CPU, using timeit with 1,000,000 iterations unless otherwise noted. Results are representative, not absolute.
| Operation | Standard math | FastMath | Improvement |
|---|---|---|---|
| sqrt(x) | ~85 ns | ~65 ns | ~23% |
| sin(x) | ~95 ns | ~72 ns | ~24% |
The improvement comes primarily from reduced attribute lookup (math.sqrt → local binding).
| Method | Time |
|---|---|
| sum() | ~78 µs |
| sum_fast() | ~62 µs |
| sum_numpy() | ~180 µs |
For small to medium iterables, pure Python outperforms NumPy due to array construction overhead.
| Implementation | Time |
|---|---|
| Naive recursion | >10 seconds |
| Cached fib() | ~0.4 ms |
Caching converts an exponential problem into a linear one.
MIT License. Use it freely, modify it boldly, and benchmark everything.
| Back | FazBrowse Home | New Git URL |