Created
March 31, 2024 20:25
-
-
Save Solorider78/252d83af840248844cedbba8ce282070 to your computer and use it in GitHub Desktop.
test_file
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
from time import time | |
from numba import jit,cuda | |
@jit(nopython=True) | |
def speed_test(): | |
print('Started...') | |
now_time = time() | |
num = 0 | |
for i in range(100000000): | |
num += 1 | |
print(num) | |
time_spent = time() - now_time | |
print(time_spent) | |
# speed_test() | |
from numba import jit, cuda | |
import numpy as np | |
# to measure exec time | |
from timeit import default_timer as timer | |
# normal function to run on cpu | |
def func(a): | |
for i in range(10000000): | |
a[i] += 1 | |
# function optimized to run on gpu | |
@jit(target_backend='cuda') | |
def func2(a): | |
for i in range(10000000): | |
a[i] += 1 | |
if __name__ == "__main__": | |
n = 100000000 | |
a = np.ones(n, dtype=np.float64) | |
start = timer() | |
func(a) | |
print("without GPU:", timer() - start) | |
start = timer() | |
func2(a) | |
print("with GPU:", timer() - start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment