An open API service indexing awesome lists of open source software.

https://github.com/thesage21/fastclass

A way to have faster encapsulation in Python
https://github.com/thesage21/fastclass

Last synced: about 1 month ago
JSON representation

A way to have faster encapsulation in Python

Awesome Lists containing this project

README

        

FastClass
=========

Sometimes a class has a few objects and their methods are called a LOT of
times. Here's an alternative way of doing 'classes' in which method calling is
faster than normal classes in Python.

A common pattern in web apps is to have a Class per table in an ORM and then
have a 'manager' class for that table. This manager is created only once and is
used throughout the app which means method execution times are what matter and
not instance creation time.

Of course this comes with drawbacks so use it wisely.

Run `python -m fastclass.bench` to get this::

Benchmarking object creation
: 100%|█████████| 1000000/1000000 [00:00<00:00, 2442567.71it/s]
: 100%|████████| 1000000/1000000 [00:00<00:00, 2235191.86it/s]
: 100%|████████| 1000000/1000000 [00:00<00:00, 1464238.55it/s]
Benchmarking object method calling and usage
: 100%|█████████| 1000000/1000000 [00:00<00:00, 1831228.34it/s]
: 100%|█████████| 1000000/1000000 [00:01<00:00, 899841.24it/s]
: 100%|█████████| 1000000/1000000 [00:01<00:00, 594763.71it/s]

Benchmarking object creation
: 100%|████████| 1000000/1000000 [00:00<00:00, 1348390.23it/s]
: 100%|████████| 1000000/1000000 [00:01<00:00, 754916.36it/s]
: 100%|████████| 1000000/1000000 [00:01<00:00, 505582.03it/s]
Benchmarking object method calling and usage
: 100%|████████| 1000000/1000000 [00:00<00:00, 2008960.64it/s]
: 100%|███████| 1000000/1000000 [00:00<00:00, 1279579.04it/s]
: 100%|████████| 1000000/1000000 [00:01<00:00, 897983.11it/s]