Use Rust regex crate in Python
Project description
Regex crate in Python
Use the fastest Regex engine ever made in Python
pip install rustregex
Important 1: Rust (cargo), Cython and a C++ compiler must be installed!
Important 2: Don't use this function in threads since the lib shares a global C++ vector for the results!
from rustcrateregex import rust_regex
from time import perf_counter
import re
import regex as cregex # Fast Regex engine with many nice features: https://pypi.org/project/regex/
# https://www.kaggle.com/datasets/vishnu0399/server-logs?resource=download&select=logfiles.log
with open(r"C:\Users\hansc\Downloads\archive\logfiles.log", mode="rb") as f:
testbytes = f.read()
# regex for bytes - currently bytes only
regex = rb"\b(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){2}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\b"
start = perf_counter()
result_rust = rust_regex((regex), (testbytes))
print(perf_counter() - start)
start = perf_counter()
result_py = [(x.start(), x.end()) for x in re.finditer((regex), testbytes)]
print(perf_counter() - start)
start = perf_counter()
result_cregex = [(x.start(), x.end()) for x in cregex.finditer((regex), testbytes)]
print(perf_counter() - start)
print("All the same: ", result_rust == result_py == result_cregex)
# Output:
# 0.6047223000005033 # Rust Regex
# 4.6312387999996645 # Python Regex
# 3.5070090999997774 # Regex
# All the same: True
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rustcrateregex-1.0.1.tar.gz
(5.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rustcrateregex-1.0.1.tar.gz.
File metadata
- Download URL: rustcrateregex-1.0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0eabb1555827522b3cb7b3eb15af51ad02dcef96b2723d101f8708b01930e2e
|
|
| MD5 |
de84fb2d0b195894071a34578b42ce65
|
|
| BLAKE2b-256 |
beedd41d462936d963fb359f3d7a567ac467e8c293437677d1e54a600697c521
|
File details
Details for the file rustcrateregex-1.0.1-py3-none-any.whl.
File metadata
- Download URL: rustcrateregex-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42280f9459e69d152ec6eb69edcc2a59dcd49724dcce3bee37e36a7f1a91985f
|
|
| MD5 |
935e2d319dc2552ad0ab15a25a85bf72
|
|
| BLAKE2b-256 |
d27d34bf0e8205833f1377c057ada7f278c8bea1854ca908ac5f6c5d65a1950d
|