当前位置:网站首页>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()
边栏推荐
猜你喜欢

1424. 对角线遍历 II

Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning

Fully Automated Delineation of Gross Tumor Volume for Head and Neck Cancer on PET-CT Using Deep Lear

Making of simple addition calculator based on pyqt5 and QT Designer

Hystrix熔断器:服务熔断与服务降级

C语言中通过sprintf()函数构造sql语句

Fabrication d'une calculatrice d'addition simple basée sur pyqt5 et Qt Designer

ORA-01950 对表空间无权限

Automatic Multi-Organ SegmVentation on Abdominal CT With Dense V-Networks

基於PyQt5和Qt Designer的簡易加法計算器的制作
随机推荐
JS获取手机型号和系统版本
2020-09-25 boost库的noncopyable,用于单例模式
详细分析PBot挖矿病毒家族行为和所利用漏洞原理,提供蓝军详细防护建议
2020-09-21 Visual Studio头文件和库目录配置
遍历vector容器中的对象的方式
Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.
General part: cognition, design and best practice of prototype design
通用分页框架
Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning
Student addition / deletion gaih
IDEA自动补全
微信小程序实现数据侦听器watch,包含销毁watch和子属性的watch
JVM之 MinorGC、 MajorGC、 FullGC、
Please use the learned knowledge to write a program to find out the password hidden in the long string below. The burial point of the password conforms to the following rules:
Segmentation of Head and Neck Tumours Using Modified U-net
GCC and makefile
2020-09-18 referer认证 url转义
CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
linux下centos7中mysql5.7安装教程
Install and configure redis in the Linux environment, and set the boot auto start