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.2.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.2.tar.gz.
File metadata
- Download URL: rustcrateregex-1.0.2.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 |
c8d59f5b10e93a391a7938eed92897bd8741630feb0c0719abd4aeb1f6ce1b70
|
|
| MD5 |
7ade109fbed5f17009d3f2750fe7c11b
|
|
| BLAKE2b-256 |
d8b8dae2ae9106a34a1b48795f06ce2836057804e4c15a5d905cadc895e45024
|
File details
Details for the file rustcrateregex-1.0.2-py3-none-any.whl.
File metadata
- Download URL: rustcrateregex-1.0.2-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 |
1e82b78ec31d060457b4b2ff74e3e439d6012b7032fd07d4289675b9c8921503
|
|
| MD5 |
e1e82936b6a43e1b6588379cd0153d45
|
|
| BLAKE2b-256 |
1a2f7c1489f74d44ffb3edbf74e25668df5e334a3f78337cf231b8c37d5ad4e4
|