栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

C++和python运行时间简单对比

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++和python运行时间简单对比

一直知道C++比python快,但自己没试过,通过打印10000次,统计下时间,对C++和python的速度进行一个粗略的对比吧。

python打印10000次
import time

time_start=time.time()
for i in range(10000):
    print(i)
time_end=time.time()
print('totally cost',time_end-time_start)

C++打印10000次
#include
#include
#include
using namespace std;
clock_t start,tend;

int main(){
	start=clock();		//程序开始计时
	int ans=0;
	for(int i=0;i<10000;i++)
		printf("%dn",i);
	tend=clock();		//程序结束用时
	double endtime=(double)(tend-start)/CLOCKS_PER_SEC;
	cout<<"Total time:"< 

 

printf和cout没有多大区别 

 结论

python运行时间大概是C++的5.7倍

同时cin的运行时间也是scanf的3.5~4倍左右,

具体可参见这篇文章scanf和cin性能的比较_信道者-CSDN博客

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/619383.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号