当前位置:网站首页>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()
边栏推荐
- LiferayPortal JSONWS反序列化漏洞(CVE-2020-7961)分析
- 详细分析PBot挖矿病毒家族行为和所利用漏洞原理,提供蓝军详细防护建议
- 2020-09-18 referer认证 url转义
- JVM之方法返回地址
- Deep Learning-based Automated Delineation of Head and Neck Malignant Lesions from PET Images
- 聊聊你理解的线程与并发
- Flutter 基础组件之 Image
- Fabrication d'une calculatrice d'addition simple basée sur pyqt5 et Qt Designer
- FreeRTOS(九)——队列
- Data governance: the solution of data governance in the data Arena
猜你喜欢

Force deduction 85 question maximum rectangle

Introduction to Chang'an chain data storage and construction of MySQL storage environment

Middle order traversal of Li Kou 94 binary tree

Perfect binary tree, complete binary tree, perfect binary tree

Flutter 基础组件之 ListView

JVM之对象的内存布局

How to traverse objects in the vector container

Constructing SQL statements by sprintf() function in C language

Kicad learning notes - shortcut keys

Chang'an chain go language smart contract writing and compilation
随机推荐
In XML layout, the button is always displayed on the top layer
linux下centos7中mysql5.7安装教程
mysql修改自动递增初始值
阿里云防火墙配置,多种设置方式(iptables和fireward)
How to traverse objects in the vector container
Flutter 基础组件之 Container
PHP内存马技术研究与查杀方法总结
分布式和集群分不清,我们讲讲两个厨子炒菜的故事
Es error nonodeavailableexception[none of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]
Wechat applet realizes store function
InvalidConnectionAttributeException异常处理
Application of decorator mode, packaging ServletRequest and adding addparameter method
Data governance: Metadata Management (Part 2)
JVM之方法的绑定机制
ImageView图片填充问题
A 3D Dual Path U-Net of Cancer Segmentation Based on MRI
数据源连接池未关闭的问题 Could not open JDBC Connection for transaction
力扣94二叉树的中序遍历
FreeRTOS(八)——时间管理
ORA-01950 对表空间无权限