当前位置:网站首页>一行代码可以做什么?
一行代码可以做什么?
2022-06-21 19:34: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
干货

边栏推荐
- 【MySQL·水滴计划】第三话- SQL的基本概念
- Kubernetes-23: explain how to make CPU manager more flexible
- Data types and usage of mediacodec
- 什么比国内现货白银更有优势?
- 【并行与分布式计算】10b_MapReduce GFS Implementation
- Kubernetes-23:详解如何将CPU Manager做到游刃有余
- 最详细整理STL之vector基础
- 期货开户平台哪家好?安全正规的期货公司有哪些?
- 用户态热补丁原理与应用
- Kubernetes-23: explain how to make CPU manager more flexible
猜你喜欢

NS32F103VBT6软硬件替代STM32F103VBT6

ASP.Net Core创建Razor页面上传多个文件(缓冲方式)

11、 Beautify the interface

Several common device communication protocols in embedded development are summarized

基于 PCA 的人脸识别系统及人脸姿态分析

Adum1401arwz-rl adenault digital signal isolation module

#夏日挑战赛# 用OpenHarmony eTS 实现一个Huawei app标准布局

【小程序】通过request实现小程序与后台asp.net的数据json传输(Post协议 图文+代码)

Extend the clean, fresh and dense bag, and put a "safety lock" on the ingredients

Intersection du vecteur et du plan
随机推荐
Quartus II 18.0 software installation package and installation tutorial
这套实时监控方案,真的太顶了!
2016 ICLR | Adversarial Autoencoders
What is more advantageous than domestic spot silver?
The final scheme of adding traceid at the C end
Convert string type to list < integer >
Intersection du vecteur et du plan
随机森林(Random Forest)学习笔记
SMILES的基本规则
Data types and usage of mediacodec
Vscode有什么好用的插件?
LeeCode70 爬楼梯
融云获取Token
总结了嵌入式开发中几种常见的设备通信协议
MySQL数据库---数据库基础
STL之vector扩容机制
What noteworthy technologies of gold: the importance of fund management
evaluating expression ‘ew.sqlSegment != null and ew.sqlSegment != ‘‘ and ew. mybaties plus问题
【并行与分布式计算】10b_MapReduce GFS Implementation
Flutter TabBarView组件