Using VBScript on local Windows 10 machine to automate some tasks. Dealing with large binary files (500 MB up to 2 GB). FileSystemObject
's file handling is abysmally slow! ADODB
is fast, but loads the entire file into memory, a big no-no since I will be running the script on multiple files (on multiple disks) concurrently.
Any alternatives?
Below is an example of FSO
taking about 26 seconds to handle a 607 MBs file. Skipping 600 MBs alone consumes a staggering 25 seconds!
Dim i, f1, f2, dT
Dim objFSO1, objStream1, objFSO2, objStream2
f1 = "OriginalFile.tmp"
f2 = "OutputFile.tmp"
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objStream1 = objFSO1.OpenTextFile(f1, 1)
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set objStream2 = objFSO2.OpenTextFile(f2, 8, True)
dT = Timer
For i = 0 To 4
'Call objStream2.Write(objStream1.Read(1048576))
Call objStream1.Read(1048576)
Next
dT = Timer - dT
Call WScript.Echo(dT & " seconds so far...")
dT = Timer
Call objStream1.Skip(629145600)
dT = Timer - dT
Call WScript.Echo("Skipping took " & dT & " seconds!")
dT = Timer
Do While Not objStream1.AtEndOfStream
'Call objStream2.Write(objStream1.Read(1048576))
Call objStream1.Read(1048576)
Loop
dT = Timer - dT
Call WScript.Echo("Another " & dT & " seconds.")
Call objStream1.Close(): Call objStream2.Close()
Set objStream1 = Nothing: Set objStream2 = Nothing
Set objFSO1 = Nothing: Set objFSO2 = Nothing
As you can see, testing while only reading the data off the disk to eliminate any possibility that the slow-down is caused by writing to disk. Same difference!