Home > other >  Python3 why repeat the open function, the execution speed will speed up?
Python3 why repeat the open function, the execution speed will speed up?

Time:09-21

I have 990 w file, named test0. CSV to test9899999. The CSV, every 10000 in sequence in a folder, a total of 999 folders,
For example I open test13456 CSV and close, takes 0.3 seconds, I once again open test13456. CSV and close, takes into 0.15 seconds, tested several files, is always the same, and I found that I went to the open recently have a file open, read speed is very fast, is this why?

CodePudding user response:


Open the file operation in modern operating systems use disk cache to speed up the repeated reading,

The operation of the open file actually not much relationship with python, but also do the cache some methods in python,

Such as the use of numpy compiling methods, after the completion of machine code version of caches function,

If again using the same type of call it, it can be reused the cached version without having to compile again

But the open method
  • Related