Python2/3 list set性能测试
前言
程序员最悲伤的故事莫过于写了一段代码,编译没错,运行出错
写机器学习最悲伤的故事莫过于饰演了一个算法,运行的时候却卡的跑不起来
这些故事我都经历过,直到刚刚我遇到了一个更悲伤的的套路:
写了段程序,为了性能,查了网上的博客,写完了自己测试却发现前辈们博客上的结果是错的.是错的,是错的
而事情的真实面貌是这样的.刚刚我查了python中list与set性能的测试,几个博客写的都是set性能几十倍甚至几百倍于list?,于是我用set写完了我的程序,写完后有点无聊决定自己测试一下set和list的性能到底差多少.然后….然后就没有然后了.
测试结果
# Python2.7.13The time of list to set : 0.000111617786487
The time of list to set2 -set3 : 7.74054381383e-05
The time of list to set2 & set3 : 3.67782744746e-05
The time of list to set2 | set3 : 0.000196293348649
The time of list to set2 != set3 : 1.71061741742e-06
The time of list to set2 == set3 : 4.27654354355e-07
The time of list to set2 in set3 : 9.23733405407e-05
The time of list to set1007 = set2 not in set3 : 6.92800054056e-05The time of set to list : 2.73698786787e-05
The time of list to list2 & list3 : 8.55308708711e-07
The time of list to list2 | list3 : 4.27654354355e-07
The time of list to list2 != list3 : 4.27654354355e-06
The time of list to list2 == list3 : 4.27654354355e-07
The time of list to list2 in list3 : 8.4247907808e-05
The time of list to list1007 = list2 not in list3 : 6.11545726728e-05
# Python3.6.1
The time of list to set : 9.451161231251095e-05
The time of list to set2 -set3 : 7.312889459474832e-05
The time of list to set2 & set3 : 5.260148558569621e-05
The time of list to set2 | set3 : 0.00010220939069090543
The time of list to set2 != set3 : 8.553087087106309e-07
The time of list to set2 == set3 : 4.276543543550986e-07
The time of list to set2 in set3 : 5.473975735747257e-05
The time of list to set1007 = set2 not in set3 : 2.352098948953888e-05The time of set to list : 1.0263704504526053e-05
The time of list to list2 & list3 : 4.276543543550986e-07
The time of list to list2 | list3 : 1.2829630630657295e-06
The time of list to list2 != list3 : 8.553087087106309e-07
The time of list to list2 == list3 : 0.0
The time of list to list2 in list3 : 2.4376298198249295e-05
The time of list to list1007 = list2 not in list3 : 2.3520989489539098e-05
多次测试结果与上文显示结果类似,从最后测试效果看:
与前辈们的测试恰恰相反.
无论是类型转变还是集合操作现在版本的list(list转set)都具有比较明显的优势,甚至一些集合操作的性能list平均要比set快上个几十几百倍=- =
不说了,我还是去把我刚写的程序中的set类型都换回list吧.
测试代码下载
百度云链接http://pan.baidu.com/s/1nvKA4Al
Python2/3 list set性能测试相关推荐
- Locust接口性能测试
前言: locust完全基于python语言,采用pure python描述测试脚本,并且http请求完全基于requests库.除了http/https协议外,locust还可以测试其他协议的系统, ...
- [雪峰磁针石博客]2018最佳12个开源或免费web服务器和客户端性能测试工具
更多参考 软件测试专家工具包2性能测试 服务器端性能 image.png Locust.io – 了解服务器端性能的好工具. 语言python3.源码 python3+ python2.7+ gith ...
- 利用pylot进行性能测试
介绍 l 基于python编写的性能测试工具,简单.易用,可以完成不太复杂的性能测试. l 目前只能基于python2.5 32位来使用,比较遗憾,而且貌似已经不在维护了,唉 安装 l 先安装pyth ...
- python locust 能压测数据库_python locust 性能测试:HOOKS钩子方法
为locust中不同类型的事件,提供的钩子方法: from locust import TaskSet, task, events, Locust from locust.clients import ...
- python3性能还低吗_Python3 vs. Python2 大作战,谁将是性能之王?
渲染 HTML 模板 django_html 测试将使用 Django 模板渲染引擎来构建一个 150x150 的 HTML 表格. 它利用了 Django 引擎的 Content 和 Templat ...
- pythonlocust使用方法_python locust 性能测试:locust安装和一些参数介绍
安装参考 https://www.cnblogs.com/fnng/p/6081798.html ps:python3.7暂不支持locust:python3安装建议克隆github上的项目 可能需要 ...
- 软件测试面试题:WEB+网络|接口测试|性能测试|自动化测试
1. http代码表,常考题目 404:找不到资源 500:服务器内部错误,无法完成请求. 501:服务器不支持请求的功能,无法完成请求. 502:充当网关或代理的服务器,从远端服务器接收到了一个无效 ...
- python locust api_性能测试工具--Locust官方文档(API)解读(全)
文章略长Locust学习笔记汇总 若有错误,请指正 内容以官网为准https://locust.io/ Locust简介 Locust是什么? Locust是一个简单易用的分布式用户负载测试工具.它用 ...
- H5游戏性能测试工具选择与实践总结
概要 本文会对本人在使用白鹭做h5游戏进行性能测试的过程送使用的工具做一些简单记录. 包括 内存,cpu,耗电,启动时间,网络监控,弱网络,流量几个方面介绍. 背景 玩吧提测有一个性能需要求列表.需要 ...
最新文章
- Java for LeetCode 067 Add Binary
- 同济计算机转专业吗,被不喜欢的专业录取了?大学想转专业需谨慎
- linux中sort命令
- 超图桌面版根据现有数据源制作一幅地图简单操作
- 随机生成一个质数的python代码_使用质数生成随机密码
- Visual.Assist.X 菜单汉化
- 不值钱的软件人才[转]
- 深入解读Linux内存管理系列(2)——内存节点的添加
- 基于SSD目标检测模型的人脸口罩识别
- java 实现短信验证码功能
- UVALive 6198 A Terribly Grimm Problem
- SSB基准测试-MySQL
- 11张好用的项目管理全流程图,支持下载保存(PMP项目管理可用)
- truetype字体怎么转换成普通字体_TrueType字体作用|如何在文档嵌入 TrueType 字体中...
- 黄灯闪烁c语言程序,交通灯控制程序 需要加一个黄灯闪烁三次 求求大神
- 线性方程组的矩阵形式
- 计算机三级在线题库,计算机三级网络技术题库(附答案)
- openlayers属性数据mysql_Openlayers+GeoServer+MySql获得JSON、GML数据的兼容性问题
- html2canvas边框无法渲染,html2canvas无法正常渲染特定的数据URI
- backlight设备树分析
热门文章
- CentOS 7.6 MySQL 8.0 RPM包方式安装及新特性介绍
- 免费的容器架构可视化工具 | 阿里云应用高可用服务 AHAS 发布重大新特性
- ZooKeeper:win7上安装单机及伪分布式安装
- 不平衡数据的数据处理方法
- 2016年DDoS攻击趋势分析报告
- 20155225 实验三《敏捷开发与XP实践》实验报告
- Caused by: java.lang.ClassNotFoundException: Didn't find class android.support.v4.view.ViewPager
- Lombok 天天用,却不知道它的原理是什么?
- 面试:Spring Boot 中的条件注解底层是如何实现的?
- 我画了35张图,就是为了让你深入理解 AQS