简体   繁体   English

用数组存储一组文件的更好方法?

[英]Better way to store a set of files with arrays?

I've accumulated a set of 500 or so files, each of which has an array and header that stores metadata. 我已经累积了500个左右的文件集,每个文件都有一个数组和存储元数据的标头。 Something like: 就像是:

2,.25,.9,26 #<-- header, which is actually cryptic metadata 1.7331,0 1.7163,0 1.7042,0 1.6951,0 1.6881,0 1.6825,0 1.678,0 1.6743,0 1.6713,0

I'd like to read these arrays into memory selectively. 我想选择性地将这些数组读入内存。 We've built a GUI that lets users select one or multiple files from disk, then each are read in to the program. 我们构建了一个GUI,使用户可以从磁盘中选择一个或多个文件,然后将每个文件读入程序。 If users want to read in all 500 files, the program is slow opening and closing each file. 如果用户要读取所有500个文件,则该程序会缓慢打开和关闭每个文件。 Therefore, my question is: will it speed up my program to store all of these in a single structure? 因此,我的问题是:将所有这些存储在单个结构中会加快程序的速度吗? Something like hdf5? 像hdf5一样? Ideally, this would have faster access than the individual files. 理想情况下,这将比单个文件具有更快的访问权限。 What is the best way to go about this? 最好的方法是什么? I haven't ever dealt with these types of considerations. 我从未处理过这些类型的注意事项。 What's the best way to speed up this bottleneck in Python? 加快Python瓶颈的最佳方法是什么? The total data is only a few MegaBytes, I'd even be amenable to storing it in the program somewhere, not just on disk (but don't know how to do this) 总数据只有几兆字节,我什至可以将其存储在程序中的某个位置,而不仅仅是存储在磁盘上(但不知道如何执行此操作)

Reading 500 files in python should not take much time, as the overall file size is around few MB. 用python读取500个文件应该不会花费太多时间,因为整个文件大小约为几MB。 Your data-structure is plain and simple in your file chunks, it ll not even take much time to parse I guess. 您的数据结构在文件块中是简单明了的,我猜它甚至不需要花费很多时间来解析。

Is the actual slowness is bcoz of opening and closing file, then there may be OS related issue (it may have very poor I/O.) 如果实际的速度是打开和关闭文件的速度,那么可能存在与操作系统相关的问题(它的I / O可能很差)。

Did you timed it like how much time it is taking to read all the files.? 您是否将其定时设置为需要花费多少时间才能读取所有文件?

You can also try using small database structures like sqllite. 您也可以尝试使用小型数据库结构,例如sqllite。 Where you can store your file data and access the required data in a fly. 您可以在其中存储文件数据并即时访问所需的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM