yarkhinephyo / python-threading-with-ctypes

Demonstrating the optimization of python with ctypes module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CTypes Demo

Code for demonstrating the usage of ctypes to speed up Python code. Blog post here.

Usage

Install GNU Make.

make compile

Test the timings with Python (3.8 used).

# Python function only
python -m timeit -n 5 -s 'import test_python as t' 't.timeit_function()'

# Python function with threading module
python -m timeit -n 5 -s 'import test_python_threading as t' 't.timeit_function()'

# C function through ctypes
python -m timeit -n 5 -s 'import test_ctypes as t' 't.timeit_function()'

# C function with pthreads through ctypes
python -m timeit -n 5 -s 'import test_ctypes_pthread as t' 't.timeit_function()'

# C function with Python threading module
python -m timeit -n 5 -s 'import test_ctypes_threading as t' 't.timeit_function()'

About

Demonstrating the optimization of python with ctypes module


Languages

Language:Python 60.3%Language:C 34.0%Language:Makefile 5.7%