当前位置:网站首页>一行代碼可以做什麼?
一行代碼可以做什麼?
2022-06-21 21:15:00 【InfoQ】
LRU
import time as tt
def func():
num = 0
for i in range(10):
num += i
return num
def main():
return func() + func() + func() + func() + func() + func() + func()
t1 = tt.time()
main()
print("Time taken: {}".format(tt.time() - t1))
# 9.05990e-6
import time as tt
import functools
@functools.lru_cache(maxsize=5)
def func():
num = 0
for i in range(10):
num += i
return num
def main():
return func() + func() + func() + func() + func() + func() + func()
t1 = tt.time()
main()
print("Time taken: {}".format(tt.time() - t1))
# 4.768371e-06
import time as tt
def fib(n):
if n <= 1:
return n
return fib(n-1) + fib(n-2)
t1 = tt.time()
fib(30)
print("Time taken: {}".format(tt.time() - t1))
# 0.2073
import time as tt
import functools
@functools.lru_cache(maxsize=5)
def fib(n):
if n <= 1:
return n
return fib(n-1) + fib(n-2)
t1 = tt.time()
fib(30)
print("Time taken: {}".format(tt.time() - t1))
# 1.811981e-05
幹貨

边栏推荐
- 向量與平面交點
- Henkel database custom operator '! ~~'
- 这套实时监控方案,真的太顶了!
- File compilation process
- What is redis hyperloglog? The use of these scenes makes me laugh like a dragon
- What plug-ins are available for vscade?
- [Patents and papers-20]: Operation Guide for electronic information declaration in Nanjing, Jiangsu Province in 2022
- [summary of smart trash cans based on Hetai ht32f52352]
- SMILES的基本规则
- 【服务器数据恢复】EMC某型号服务器raid5数据恢复案例
猜你喜欢

4.3寸触摸屏智能网络中控主机有哪些应用

This real-time monitoring scheme is really excellent!

如何有序协同和管理多个研发项目?

UIButton实现左文字右图片

C语言回调函数到底是怎么回事?

AXI_Bus_Matrix_4x4 设计 - 逻辑设计部分

Data path: three people walk, there must be my teacher!

Some shaders in AB package do not trigger the callback of ipreprocessshaders

libtorch显存管理示例

Cluster I -- LVS load balancing cluster NAT mode and LVS load balancing actual deployment
随机推荐
The final scheme of adding traceid at the C end
行业首家!极氪APP获中国网络安全审查技术与认证中心权威认证
带你区分几种并行
十一、美化界面
Class loading process of JVM
混合云演习常见案例
Introduction to internet protocol -- five layer model
Cocoapods安装(Xcode8.0之后,无限卡在Setting up CocoaPods master repo)
纵横网络靶场社区-Modbus协议
MySQL数据库---索引
如何有序协同和管理多个研发项目?
Xcode插件管理工具Alcatraz
What is redis hyperloglog? The use of these scenes makes me laugh like a dragon
It is said that the price of the iPhone 14 will rise; TikTok US user data is transferred to Oracle, and bytes cannot be accessed; Seatunnel 2.1.2 releases geek headlines
Flutter TabBarView组件
Leecode435 non overlapping interval
Simulate the input and get the contents of print output
修改UE4缓存路径,缓解c盘压力
MySQl学习(从入门到精通 1.2)
New hybrid architecture iformer! Flexible migration of convolution and maximum pooling to transformer