import time
defone_cycle():
num =0for i inrange(1,1000000):
num +=i
return num
defdouble_cycle():
num =0for i inrange(1000):for j inrange(1000):
num +=i*j
return num
deftriple_cycle():
num =0for i inrange(100):for j inrange(100):for k inrange(100):
num += i*j*k
return num
if __name__=="__main__":
start_time = time.time()for i inrange(100):
one_cycle()
end_time = time.time()print("one_cycle函数运行时间:",(end_time-start_time)/100)
start_time = time.time()for i inrange(100):
double_cycle()
end_time = time.time()print("double_cycle函数运行时间:",(end_time-start_time)/100)
start_time = time.time()for i inrange(100):
triple_cycle()
end_time = time.time()print("triple_cycle函数运行时间:",(end_time-start_time)/100)
import time
import numba
import warnings
warnings.filterwarnings('ignore')@numba.jitdefone_cycle():
num =0for i inrange(1,1000000):
num +=i
return num
@numba.jitdefdouble_cycle():
num =0for i inrange(1000):for j inrange(1000):
num +=i*j
return num
@numba.jitdeftriple_cycle():
num =0for i inrange(100):for j inrange(100):for k inrange(100):
num += i*j*k
return num
if __name__=="__main__":
start_time = time.time()for i inrange(100):
one_cycle()
end_time = time.time()print("one_cycle函数运行时间:",(end_time-start_time)/100)
start_time = time.time()for i inrange(100):
double_cycle()
end_time = time.time()print("double_cycle函数运行时间:",(end_time-start_time)/100)
start_time = time.time()for i inrange(100):
triple_cycle()
end_time = time.time()print("triple_cycle函数运行时间:",(end_time-start_time)/100)
欢迎大家来到 Java Web 开发的学习之旅!在前面的博客中,我们已经学习了 Servlet、JSP、Filter 等重要的概念和技术。今天,我们将深入探讨 Java Web 开发中另一个重要的组成部分——Listener(监听器),具体来…
题目大意 题目思路
感性理解一下,将一个数的平方变成多个数平方的和,为了使代价最小,这些数的大小应该尽可能的平均。
我们可以将 ∣ b i − a i ∣ |b_i-a_i| ∣bi−ai∣放入大根堆,同时将这个数划分的次数以及多划分一段减…