日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python2/3 list set性能测试

發布時間:2025/3/21 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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性能测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。