-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v0.6.2 #33
Conversation
Codecov Report
@@ Coverage Diff @@
## master #33 +/- ##
==========================================
+ Coverage 85.58% 86.36% +0.78%
==========================================
Files 18 19 +1
Lines 853 851 -2
==========================================
+ Hits 730 735 +5
+ Misses 123 116 -7
Continue to review full report at Codecov.
|
this switches to a regex-based approach. this will be much slower, but will probably be more what we're looking for... @vreuter any objections? |
That's an overkill for such insignificant problem... but ran couple of tests and you're right, regex is slower since it depends on the input length ( import time
from urllib.parse import urlparse
from ubiquerg import is_url
def check_time(fun, n=10000):
results = []
for _ in range(1, n):
start = time.time()
fun(string)
end = time.time()
results.append((end - start))
return (sum(results) / n) * 1000
def is_url_old(string):
try:
result = urlparse(string)
return all([result.scheme, result.netloc, result.path])
except:
return False
strings = [f"http://www.g{'o' * 10000}gle.com'", f"http://www.g{'o' * 5000}gle.com'", "http://www.google.com", ""]
for string in strings:
print(f"new time: {check_time(fun=is_url)}ms")
print(f"old time: {check_time(fun=is_url_old)}ms\n")
|
return urlparse(maybe_url).scheme != "" | ||
# from Django 1.3.x | ||
# https://github.com/django/django/blob/6726d750979a7c29e0dd866b4ea367eef7c8a420/django/core/validators.py#L45-L51 | ||
regex = re.compile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave an optional suggestion as a comment but looks good, w/e you guys think as far as tradeoff b/w runtime vs. behavior of the implementation.
fix #32