当前位置:网站首页>Language characteristics
Language characteristics
2022-06-29 10:00:00 【qqq2018】
Why? c++ Than python fast ?
1.Python After more layers , Even numbers object.
2.Python It's the interpretation of execution , And physical machines CPU There is an interpreter layer between them , and C++ It's compiled , It's the machine code directly , The compiler can also perform some optimizations during compilation .
python Multithreading is pseudo multithreading
The interpreter provides GIL( Global Interpreter Lock , Global interpreter lock ) Ensure thread data synchronization , Only one thread is executing at a time .
You can use multiple processes to achieve parallelism .
# Multithreading
from threading import Thread
def spawn_n_threads(n, target):
threads = []
for _ in range(n):
thread = Thread(target=target)
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
# Multi process
from multiprocessing import Process
def spawn_n_processes(n, target):
threads = []
for _ in range(n):
thread = Process(target=target)
thread.start()
threads.append(thread)
for thread in threads:
thread.join()python Decorator
In order to reuse the code and call the original function to realize the new function
# Pass in a function , Returns a new decorated function
def timer(func):
def deco():
print("add something 1")
func()
print("add something 2")
return deco
# use @ Symbol tell python,foo This function is timer Decorated , call foo Will call directly timer(foo)
@timer
def foo():
print("1000lines")
foo()
边栏推荐
- Causes and solutions of error reporting by using startactivity() method outside the activity
- 力扣94二叉树的中序遍历
- Recyclerview refreshes blinks and crashes when deleting items
- A 2.5D Cancer Segmentation for MRI Images Based on U-Net
- Idea debugging fails, reporting jdwp no transports initialized, jvmtierror=agent_ ERROR_ TRANSPORT_ LOAD(196)
- 详细分析PBot挖矿病毒家族行为和所利用漏洞原理,提供蓝军详细防护建议
- IDEA自动补全
- A 2.5D Cancer Segmentation for MRI Images Based on U-Net
- 证券账号开户安全吗?是靠谱的吗?
- 通用分页框架
猜你喜欢

Middle order traversal of Li Kou 94 binary tree

JVM之方法返回地址

linux环境下安装配置redis,并设置开机自启动

Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.

Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images

Generic paging framework

CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION

力扣94二叉树的中序遍历

Segmentation of Head and Neck Tumours Using Modified U-net

kdevelop新建工程
随机推荐
Generic paging framework
JS获取手机型号和系统版本
Recyclerview refreshes blinks and crashes when deleting items
我想知道如何免费网上注册股票开户?另外,手机开户安全么?
内网穿透工具frp使用入门
详细分析PBot挖矿病毒家族行为和所利用漏洞原理,提供蓝军详细防护建议
Mysql5.7 installation tutorial in centos7 under Linux
MySQL modify auto increment initial value
Construction and use of Changan chain go language smart contract environment
CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
F5 BIG-IP iControl REST命令执行(CVE-2022-1388)
监控数据源连接池使用情况
通用分页框架
Data governance: data standard management (Part III)
Making of simple addition calculator based on pyqt5 and QT Designer
linux环境下安装配置redis,并设置开机自启动
How to traverse objects in the vector container
cenos7下搭建LAMP环境
linux下centos7中mysql5.7安装教程
Do you know what BFD is? This article explains the principle and usage scenarios of BFD protocol in detail