-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdcbb68
commit 7277b19
Showing
18 changed files
with
1,315 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
import warnings | ||
warnings.filterwarnings('ignore', message='Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning') | ||
|
||
__version__ = "0.1.12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,8 @@ enabled = true | |
aniworld_to = true | ||
serienstream_to = false | ||
|
||
[settings.ui] | ||
dark = true | ||
|
||
[meta] | ||
version = "0.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import re | ||
import time | ||
from bs4 import BeautifulSoup | ||
|
||
html = ''' | ||
<input type="hidden" id="recaptcha-token" value="03AFcWeA63UNMqNIJHmaB6Xj6nRTgNHQisxw1SbdigJVrSWeexc8cCphD9Pc6JSeKSaaKZ3xrx_KXB14FXzO-HCNoG_DyJssDdZfeXuQnlpV5LWaVTc-02MqlYD8B0857IoymZ_aE7jbAErFjWJW4rmc_iwsi9NB8ELWFoMkv_rlT2baeDt5OG2FUosCIHSpzqq6CcKkKSk1MyVfV3XQyABbvvTfREOc3oVNhOKOD1foy0yk7p19ZhoANtlWX-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lj0Ti0w5M2WVQ0v87oHjlStmj17vOAge4wcAN8kQZ-BrqWYSMO6DtoL45_3TdD42V-2hG0hOcxV8HsOYHnoymZqHg_WApHsENg5CfO6OywSNbRnNUaE9dDxsqt9KAUG0g8HIMGzuilefp2EdVTyiNbVtjcuBTg3agGvcS7UMsRLDXAyCqSRI3CLcBVvDaTuQXKovxUZpzDEtQQqtUUmvSuNbK0rHCpBKSQubqONThBTeegy3o3CIuKiA"> | ||
''' | ||
|
||
|
||
# String manipulation method | ||
def extract_value_string(html): | ||
start = html.find('id="recaptcha-token"') | ||
if start != -1: | ||
start = html.find('value="', start) + len('value="') | ||
end = html.find('"', start) | ||
return html[start:end] | ||
return None | ||
|
||
|
||
# Regex method | ||
def extract_value_regex(html): | ||
pattern = r'<input[^>]*id="recaptcha-token"[^>]*value="([^"]+)"' | ||
match = re.search(pattern, html) | ||
if match: | ||
return match.group(1) | ||
return None | ||
|
||
|
||
# BeautifulSoup method | ||
def extract_value_bs4(html): | ||
soup = BeautifulSoup(html, 'html.parser') | ||
input_tag = soup.find('input', {'id': 'recaptcha-token'}) | ||
if input_tag: | ||
return input_tag.get('value') | ||
return None | ||
|
||
|
||
# Measure performance of string manipulation method | ||
start_time = time.time() | ||
for _ in range(100000): | ||
token = extract_value_string(html) | ||
string_duration = time.time() - start_time | ||
|
||
# Measure performance of regex method | ||
start_time = time.time() | ||
for _ in range(100000): | ||
token = extract_value_regex(html) | ||
regex_duration = time.time() - start_time | ||
|
||
# Measure performance of BeautifulSoup method | ||
start_time = time.time() | ||
for _ in range(100000): | ||
token = extract_value_bs4(html) | ||
bs4_duration = time.time() - start_time | ||
|
||
print(f"String manipulation duration: {string_duration:.6f} seconds") | ||
print(f"Regex duration: {regex_duration:.6f} seconds") | ||
print(f"BeautifulSoup duration: {bs4_duration:.6f} seconds") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "benchmark" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
may_minihttp = "0.1.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import time | ||
import asyncio | ||
import requests | ||
import httpx | ||
import aiohttp | ||
import urllib.request | ||
import http.client | ||
|
||
HOST = "127.0.0.1" | ||
PORT = 8080 | ||
URL = f"http://{HOST}:{PORT}" | ||
|
||
|
||
def benchmark_http_client_sync(): | ||
# Has no sessions | ||
start_time = time.time() | ||
for _ in range(1000): | ||
conn = http.client.HTTPConnection(HOST, port=PORT) | ||
conn.request("GET", "/") | ||
conn.close() | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
def benchmark_requests(): | ||
start_time = time.time() | ||
for _ in range(100): | ||
with requests.Session() as session: | ||
session.get(URL) | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
async def benchmark_aiohttp(): | ||
start_time = time.time() | ||
for _ in range(100): | ||
async with aiohttp.ClientSession() as session: | ||
await session.get(URL) | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
def benchmark_httpx(): | ||
start_time = time.time() | ||
for _ in range(100): | ||
with httpx.Client() as client: | ||
client.get(URL) | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
def benchmark_urllib(): | ||
start_time = time.time() | ||
for _ in range(100): | ||
opener = urllib.request.build_opener() | ||
opener.open(URL) | ||
opener.close() | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
if __name__ == "__main__": | ||
sync_time = benchmark_requests() | ||
async_time = asyncio.run(benchmark_aiohttp()) | ||
httpx_time = benchmark_httpx() | ||
urllib_time = benchmark_urllib() | ||
http_client_sync_time = benchmark_http_client_sync() | ||
|
||
print(f"HTTP: {http_client_sync_time} seconds") | ||
print(f"Requests: {sync_time} seconds") | ||
print(f"Aiohttp: {async_time} seconds") | ||
print(f"HTTPX: {httpx_time} seconds") | ||
print(f"Urllib: {urllib_time} seconds") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import time | ||
import asyncio | ||
import requests | ||
import httpx | ||
import aiohttp | ||
import urllib.request | ||
import http.client | ||
|
||
HOST = "127.0.0.1" | ||
PORT = 8080 | ||
URL = f"http://{HOST}:{PORT}" | ||
|
||
|
||
def benchmark_http_client_sync(): | ||
start_time = time.time() | ||
for _ in range(1000): | ||
conn = http.client.HTTPConnection(HOST, port=PORT) | ||
conn.request("GET", "/") | ||
conn.close() | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
def benchmark_requests(): | ||
start_time = time.time() | ||
with requests.Session() as session: | ||
for _ in range(1000): | ||
session.get(URL) | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
async def benchmark_aiohttp(): | ||
start_time = time.time() | ||
async with aiohttp.ClientSession() as session: | ||
for _ in range(1000): | ||
await session.get(URL) | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
def benchmark_httpx(): | ||
start_time = time.time() | ||
with httpx.Client() as client: | ||
for _ in range(1000): | ||
client.get(URL) | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
def benchmark_urllib(): | ||
start_time = time.time() | ||
opener = urllib.request.build_opener() | ||
for _ in range(1000): | ||
opener.open(URL) | ||
opener.close() | ||
end_time = time.time() | ||
return end_time - start_time | ||
|
||
|
||
if __name__ == "__main__": | ||
sync_time = benchmark_requests() | ||
async_time = asyncio.run(benchmark_aiohttp()) | ||
httpx_time = benchmark_httpx() | ||
urllib_time = benchmark_urllib() | ||
http_client_sync_time = benchmark_http_client_sync() | ||
|
||
print(f"HTTP: {http_client_sync_time} seconds") | ||
print(f"Requests: {sync_time} seconds") | ||
print(f"Aiohttp: {async_time} seconds") | ||
print(f"HTTPX: {httpx_time} seconds") | ||
print(f"Urllib: {urllib_time} seconds") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
extern crate may_minihttp; | ||
|
||
use std::io; | ||
use may_minihttp::{HttpServer, HttpService, Request, Response}; | ||
|
||
#[derive(Clone)] | ||
struct HelloWorld; | ||
|
||
impl HttpService for HelloWorld { | ||
fn call(&mut self, _req: Request, _res: &mut Response) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
let server = HttpServer(HelloWorld).start("0.0.0.0:8080").unwrap(); | ||
server.join().unwrap(); | ||
} |
Oops, something went wrong.