Python Pickle 加载每次迭代花费的时间更长
我有一个大小为 4mb 的 gzip 腌制文件。每次我打开文件并加载它时,解封所需的时间都会更长。文件的内容永远不会改变并且大小保持不变。
测试时间:
第一次运行:27.5 秒
第二次运行:44.1s
第三次运行:52.7s
我正在使用的代码如下:
f = gzip.open( filepath, "rb" )
pickleFile = cPickle.Unpickler( f )
paData = pickleFile.load()
f.close()
知道为什么每次运行时加载时间更长吗?
I have a gzip'd pickled file that is 4mb in size. Each time I open the file and load it the time it takes to unpickle takes longer. The contents of the file never change and the size stays the same.
Test Times:
1st Run: 27.5s
2nd Run: 44.1s
3rd Run: 52.7s
The code I'm using is as follows:
f = gzip.open( filepath, "rb" )
pickleFile = cPickle.Unpickler( f )
paData = pickleFile.load()
f.close()
Any idea why it is taking longer to load each time I run?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了两个测试 pickle 文件 3MB 和 22MB,并将其压缩。
我不明白你在做什么,因为我刚刚做了一个测试,这段代码:
总是打印出与我运行它相同的内容。
3 MB 文件:
22MB 文件:
I created two test pickle file 3MBs and 22MBs, and zipped it.
I don't understand what you are doing because I just did a test and this code:
Always prints out the same as I run it.
3 MB File:
22MB File: