Last active
May 18, 2021 16:11
-
-
Save vulnersCom/07c90f2ad1cf95f340916b62b78552e5 to your computer and use it in GitHub Desktop.
Palindrome test
This file contains hidden or 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
import os, psutil | |
import random | |
import string | |
large_string = "".join([random.choice(string.ascii_letters + string.punctuation) for _ in range(0, 500000)]) | |
process = psutil.Process(os.getpid()) | |
def is_palindrome(str_array): | |
str_array = str_array.lower() | |
one_way_gen = filter(lambda i:i.isalpha(), str_array) | |
reverse_way_gen = filter(lambda i:i.isalpha(), reversed(str_array)) | |
return all(a==b for a,b in zip(one_way_gen, reverse_way_gen)) | |
# Aprox 14909440 for empty program just generating string | |
# Same value for 14352384 making generic Facebook kind of comparison | |
# 14880768 for generator-based comparison | |
looks_like_reversed_is_iterator = is_palindrome(large_string) | |
print(looks_like_reversed_is_iterator) | |
print(process.memory_info().rss) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment