Compare commits

...

4 Commits

Author SHA1 Message Date
388be36ab1 Update example_of_timer.py 2025-03-24 18:07:24 +08:00
1a5d874ac0 Update example_of_time_logging.py 2025-03-24 18:02:45 +08:00
b85ae814c3 update 2025-03-24 17:52:33 +08:00
7b07bd90bc Create numba_example.py 2025-03-23 22:16:38 +08:00
5 changed files with 44 additions and 8 deletions

View File

@ -0,0 +1,20 @@
import numpy as np
import time
numpy_array = np.arange(0,1e5,1)
times = 1000
from numba import jit
from numba import prange
@jit(nopython=True, parallel=True)
def numba_example(numpy_array):
sum = 0
for i in prange(len(numpy_array)):
sum += numpy_array[i]
return sum
start = time.time()
for _ in range(times):
result = numba_example(numpy_array)
end = time.time()
print(f'运行时间:{end - start}')

View File

@ -0,0 +1,16 @@
# 检查是否为厄米矩阵相对误差为1e-5)
import guan
matrix1 = [
[2, 1.00001-1j],
[1+1j, 1]
]
print(guan.is_hermitian(matrix1))
matrix2 = [
[2, 1.00002-1j],
[1+1j, 1]
]
print(guan.is_hermitian(matrix2))

View File

@ -1,7 +1,7 @@
# 运行统计 # 运行时间日志
import guan import guan
import time import time
guan.statistics_with_day_and_time(content='start') guan.logging_with_day_and_time(content='start')
for i in range(3): for i in range(3):
time.sleep(5) time.sleep(5)
guan.statistics_with_day_and_time(f'end_of_{i}') guan.logging_with_day_and_time(f'end_of_{i}')

View File

@ -5,11 +5,11 @@ import guan
def test1(a, b): def test1(a, b):
import time import time
print(a) print(a)
time.sleep(2) time.sleep(1)
print(b) print(b)
print('Run finished.') print('Run finished.')
for _ in range(3): for _ in range(2):
test1(10, b=20) test1(10, b=20)
print() print()
@ -17,9 +17,9 @@ print()
def test2(a, b): def test2(a, b):
import time import time
print(a) print(a)
time.sleep(2) time.sleep(1)
print(b) print(b)
print('Run finished.') print('Run finished.')
for _ in range(3): for _ in range(2):
guan.timer(test2, 10, b=20) guan.timer(test2, 100, b=200)