Use Rust regex crate in Python
Project description
Regex crate in Python
Use the fastest Regex engine ever made in Python
pip install rustcrateregex
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.4.tar.gz
(7.6 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.4.tar.gz.
File metadata
- Download URL: rustcrateregex-1.0.4.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bd2ae1a2ffbc2301e94c9949c95dc4cd44fa830d8935058eb0a5abc8fe6c7ce
|
|
| MD5 |
39d4f2465590148bcca3377b8b327958
|
|
| BLAKE2b-256 |
ce1e7983772c88494e6a2aa45536554f7bc8eea4ec2f76c80915d562c98b4766
|
File details
Details for the file rustcrateregex-1.0.4-py3-none-any.whl.
File metadata
- Download URL: rustcrateregex-1.0.4-py3-none-any.whl
- Upload date:
- Size: 10.1 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 |
972b807a9c9c5c51715bf73af8e2c306483e677ecbcaecf6651505bc8250caaf
|
|
| MD5 |
10602fdb9892026bd9193925ca3a8fa9
|
|
| BLAKE2b-256 |
dd964106f18c0f22c5c7bb710343d7896b62034cecb473412563e7b10d115efb
|