https://github.com/matthewandretaylor/fastqueue
Fast Python queues
https://github.com/matthewandretaylor/fastqueue
cpython cpython-extensions performance python python3 queue
Last synced: 26 days ago
JSON representation
Fast Python queues
- Host: GitHub
- URL: https://github.com/matthewandretaylor/fastqueue
- Owner: MatthewAndreTaylor
- License: mit
- Created: 2023-04-13T05:40:25.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-26T22:28:07.000Z (11 months ago)
- Last Synced: 2025-06-19T01:50:44.891Z (27 days ago)
- Topics: cpython, cpython-extensions, performance, python, python3, queue
- Language: C
- Homepage: https://matthewandretaylor.github.io/fastqueue/
- Size: 582 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastqueue
[](https://github.com/MatthewAndreTaylor/fastqueue/actions)
[](https://github.com/MatthewAndreTaylor/fastqueue/)
[](https://github.com/MatthewAndreTaylor/fastqueue/blob/master/LICENSE)\
[](https://pypi.org/project/fastqueue-lib/)Single-ended fast queues built in C tuned for Python.
## Requirements
- `python 3.7+`
## Installation
To install fastqueue, using [pip](https://pypi.org/project/fastqueue-lib):
```bash
pip install fastqueue-lib
```## Quickstart
For general use cases `fastqueue.Queue()` objects are tuned to perform well.
The enqueue and dequeue methods perform well over a large sequence of arbitrary operations.
`fastqueue.Queue()` supports many standard sequence methods similar to lists.
`fastqueue.Queue()` minimizes memory usage but maintains the fast queue speeds.```py
>>> from fastqueue import Queue
>>> queue = Queue()
>>> queue.extend(['🚒', '🛴'])
>>> queue[0]
'🚒'
>>> '🛴' in queue
True
>>> queue.enqueue('🚅')
>>> queue.enqueue('🚗')
>>> queue[-1]
'🚗'
>>> [queue.dequeue() for _ in range(len(queue)) ]
['🚒', '🛴', '🚅', '🚗']
```For more specialized cases `fastqueue.QueueC()` objects are tuned to perform well.
The interface for `fastqueue.QueueC()` is identical to `fastqueue.Queue()`.
The enqueue and dequeue methods perform similarly well over a large sequence of arbitrary operations.
`fastqueue.QueueC()` handles memory differently by doubling the capacity when full.
This increases the complexity but maintains fast amortized cost.
The benefit of this approach is even faster `__getitem__` and `__setitem__` speeds```py
>>> from fastqueue import QueueC>>> queue_c = QueueC()
>>> queue_c.extend(['🚒', '🛴'])
>>> queue_c[0]
'🚒'
>>> '🛴' in queue_c
True
>>> queue_c.enqueue('🚅')
>>> queue_c.enqueue('🚗')
>>> queue_c[-1]
'🚗'
>>> [queue_c.dequeue() for _ in range(len(queue_c)) ]
['🚒', '🛴', '🚅', '🚗']
```Another alternative is `fastqueue.LockQueue()` which supports all queue operations.
`fastqueue.LockQueue()` is built as a thread-safe alternative to the other queue types.## Example Benchmarks
### Queue operations
Ubuntu

Windows

### Iteration
Ubuntu

Windows

