Skip to main content

Ultra-fast inspect functions for Python

Project description

uinspect

This is a small Python package that offers fast runtime inspection similar to that of inspect module in Python. To install, simply do

pip install uinspect

benchmark

The following benchmark is generated from running the scripts in benchmark/.

Task name

uinspect method1

uinspect method2

inspect

speedup

Cost (us/op)

Source location

uinspect.get_location() - 0.21s

uinspect.Frame() - 0.48s

16.43s

79.7x

0.21 us/op

Locals

uinspect.Frame().locals - 0.99s

N/A

0.82s

0.82x

0.99 us/op

Locals diff

uinspect.Frame(2).collect_vars() - 2.94s

N/A

1.20s

0.41x

2.94 us/op

Frame walking

uinspect.FrameWalker({}).get_location() - 1.45s

N/A

52.27s

35.9x

1.46 us/op

It turns out that the uinspect does not speed up the local variable calculation. This is because we have to run an expensive Python C API call regardless of whether it’s uinspect or inspect. As a result, the overhead is caused by the fact that uinspect needs to convert Python object to C++ object.

The lesson is to use inspect module for any local variables related manipulation since it’s faster, but use uinspect to obtain source location.

install from source

git clone https://github.com/Kuree/uinspect.git
cd uinspect
git submodule update --init
python setup.py install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

uinspect-0.0.5-cp311-cp311-win_amd64.whl (78.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

uinspect-0.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (120.4 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

uinspect-0.0.5-cp311-cp311-macosx_10_15_universal2.whl (131.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.15+ universal2 (ARM64, x86-64)

uinspect-0.0.5-cp310-cp310-win_amd64.whl (78.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

uinspect-0.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (120.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

uinspect-0.0.5-cp310-cp310-macosx_10_15_universal2.whl (130.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ universal2 (ARM64, x86-64)

uinspect-0.0.5-cp39-cp39-win_amd64.whl (78.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

uinspect-0.0.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (120.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

uinspect-0.0.5-cp39-cp39-macosx_10_15_universal2.whl (131.2 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ universal2 (ARM64, x86-64)

uinspect-0.0.5-cp38-cp38-win_amd64.whl (78.5 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

uinspect-0.0.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (120.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

uinspect-0.0.5-cp38-cp38-macosx_10_15_universal2.whl (130.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.15+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page