<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">2018-04-11 2:03 GMT+02:00 Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span>:</div><div class="gmail_quote">[snip]<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I shouldn't think that the number of files on disk is very important, <br>
now that they're hidden away in the __pycache__ directory where they can <br>
be ignored by humans. Even venerable old FAT32 has a limit of 65,534 <br>
files in a single folder, and 268,435,437 on the entire volume. So <br>
unless the std lib expands to 16000+ modules, the number of files in the <br>
__pycache__ directory ought to be well below that limit.<br></blockquote><div>[snip] </div><div><br></div><div>Hi all,</div><div><br></div><div>Just for information for everyone:</div><div>(I was a VMS system manager  more than a decade ago, and I know that Win NT (at least the core) is developed by a former VMS engineer. NTFS  is created on the bases of Files-11 (Files-11B) file system. And in both file systems the directory is a tree (in Files-11 it is a B-tree, maybe in NTFS it is different tree, but tree). Holding the files ordered alphabetically.</div><div>And if there are "too much" files then accessing files will be slower. (check for example the windows\system32 folder).</div><div><br></div><div>Of course it is not matter if there are some hundred or 1-2 thousand files. But the too much matters.</div><div><br></div><div>I did a little measurement (intentionally not used functions not to make the result wrong):</div><div><br></div><div><br></div><div><pre style="background-color:rgb(231,231,231);color:rgb(0,0,0);font-family:Consolas"><br><span style="color:rgb(0,0,128);font-weight:bold">import </span>os<br><span style="color:rgb(0,0,128);font-weight:bold">import </span>time<br><br><span style="color:rgb(0,0,128);font-weight:bold">try</span>:<br>    os.mkdir(<span style="color:rgb(0,128,128);font-weight:bold">'tmp_thousands_of_files'</span>)<br><span style="color:rgb(0,0,128);font-weight:bold">except</span>:<br>    <span style="color:rgb(0,0,128);font-weight:bold">pass<br></span><span style="color:rgb(0,0,128);font-weight:bold"><br></span>name1 = <span style="color:rgb(0,0,255)">10001<br></span><span style="color:rgb(0,0,255)"><br></span>start = time.time()<br>file_name = <span style="color:rgb(0,128,128);font-weight:bold">'tmp_thousands_of_files/' </span>+ str(name1)<br>f = open(file_name, <span style="color:rgb(0,128,128);font-weight:bold">'w'</span>)<br>f.write(<span style="color:rgb(0,128,128);font-weight:bold">'aaa'</span>)<br>f.close()<br><br>stop = time.time()<br><br>file_time = stop-start<br><br>print(<span style="color:rgb(0,128,128);font-weight:bold">f'one file time {file_time} </span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold"> {start} </span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold"> {stop}'</span>)<br><br><br><span style="color:rgb(0,0,128);font-weight:bold">for </span>i <span style="color:rgb(0,0,128);font-weight:bold">in </span>range(<span style="color:rgb(0,0,255)">10002</span>, <span style="color:rgb(0,0,255)">20000</span>):<br>    file_name = <span style="color:rgb(0,128,128);font-weight:bold">'tmp_thousands_of_files/' </span>+ str(i)<br>    f = open(file_name, <span style="color:rgb(0,128,128);font-weight:bold">'w'</span>)<br>    f.write(<span style="color:rgb(0,128,128);font-weight:bold">'aaa'</span>)<br>    f.close()<br><br><br><br>name2 = <span style="color:rgb(0,0,255)">10000<br></span><span style="color:rgb(0,0,255)"><br></span>start = time.time()<br>file_name = <span style="color:rgb(0,128,128);font-weight:bold">'tmp_thousands_of_files/' </span>+ str(name2)<br>f = open(file_name, <span style="color:rgb(0,128,128);font-weight:bold">'w'</span>)<br>f.write(<span style="color:rgb(0,128,128);font-weight:bold">'aaa'</span>)<br>f.close()<br><br>stop = time.time()<br><br>file_time = stop-start<br>print(<span style="color:rgb(0,128,128);font-weight:bold">f'after 10k, name before {file_time} </span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold"> {start} </span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold"> {stop}'</span>)<br><br><br>name3 = <span style="color:rgb(0,0,255)">20010<br></span><span style="color:rgb(0,0,255)"><br></span>start = time.time()<br>file_name = <span style="color:rgb(0,128,128);font-weight:bold">'tmp_thousands_of_files/' </span>+ str(name3)<br>f = open(file_name, <span style="color:rgb(0,128,128);font-weight:bold">'w'</span>)<br>f.write(<span style="color:rgb(0,128,128);font-weight:bold">'aaa'</span>)<br>f.close()<br><br>stop = time.time()<br><br>file_time = stop-start<br>print(<span style="color:rgb(0,128,128);font-weight:bold">f'after 10k, name after {file_time} </span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold"> {start} </span><span style="color:rgb(0,0,128);font-weight:bold">\n</span><span style="color:rgb(0,128,128);font-weight:bold"> {stop}'</span>)<br><br><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold">result<br></span><span style="color:rgb(0,128,128);font-weight:bold"><br></span><span style="color:rgb(0,128,128);font-weight:bold">c:\>python several_files_in_one_folder.py<br></span><span style="color:rgb(0,128,128);font-weight:bold">one file time 0.0<br></span><span style="color:rgb(0,128,128);font-weight:bold"> 1523476699.5144918<br></span><span style="color:rgb(0,128,128);font-weight:bold"> 1523476699.5144918<br></span><span style="color:rgb(0,128,128);font-weight:bold">after 10k, name before 0.015625953674316406<br></span><span style="color:rgb(0,128,128);font-weight:bold"> 1523476714.622918<br></span><span style="color:rgb(0,128,128);font-weight:bold"> 1523476714.6385438<br></span><span style="color:rgb(0,128,128);font-weight:bold">after 10k, name after 0.0<br></span><span style="color:rgb(0,128,128);font-weight:bold"> 1523476714.6385438<br></span><span style="color:rgb(0,128,128);font-weight:bold"> 1523476714.6385438<br></span><span style="color:rgb(0,128,128);font-weight:bold">"""<br></span><span style="color:rgb(0,128,128);font-weight:bold"><br></span></pre><br></div><div>used: Python 3.6.1, windows 8.1, SSD drive</div><div><br></div><div>As you can see, when there an insertion into the beginning of the tree it is much slower then adding to the end. (yes, I know the list insertion is slow as well, but I saw VMS directory with 50k files, and the dir command gave 5-10 files then waited some seconds before the next 5-10 files ... ;-) )</div><div><br></div><div><br></div><div>BR,</div><div>George<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></div></div>