Created
January 8, 2023 15:44
-
-
Save CrimsonScythe/dd2d85535067513dd9453f4ca91c7bbe to your computer and use it in GitHub Desktop.
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
def profile(func): | |
from functools import wraps | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
from line_profiler import LineProfiler | |
prof = LineProfiler() | |
try: | |
return prof(func)(*args, **kwargs) | |
finally: | |
prof.print_stats() | |
return wrapper | |
@profile | |
def square_my_num(): | |
universe = np.arange(100000) | |
numbers = np.random.rand(100000) | |
filtered_nums=[] | |
for number in numbers: | |
if number in universe: | |
filtered_nums.append(number) | |
squares = [] | |
for number in filtered_nums: | |
squares.append(number ** 2) | |
@profile | |
def matrix_stuff(): | |
a = np.random.rand(5000,5000) | |
for i in range(a.shape[0]): | |
for j in range(a.shape[1]): | |
if a[i][j] < 0: | |
a[i][j] = a[i][j]*0 | |
else: | |
a[i][j] = a[i][j]*1 | |
def main(): | |
matrix_stuff() | |
square_my_num() | |
# square_my_num_faster() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment