Commit 1378c1bb by mozheng

工程初始化

parents
.vscode/*
\ No newline at end of file
from numba import jit
from numpy import arange
import time
@jit
def numba_sum(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
def sum(arr):
M, N = arr.shape
result = 0.0
for i in range(M):
for j in range(N):
result += arr[i,j]
return result
if __name__ == "__main__":
a = arange(9).reshape(3,3)
start_time = time.time()
for i in range(10000000):
numba_sum(a)
end_time = time.time()
print ("使用numba:", end_time - start_time)
start_time = time.time()
for i in range(10000000):
sum(a)
end_time = time.time()
print ("使用cpu:", end_time - start_time)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment