lzma unpack speed, extremely slow on big Archiv
Posted: Sun Apr 16, 2023 9:02 pm
When I unpack a large archive with Purebasic, it takes a very long time. (There is only one file in the archive)
Here is a comparison with the console version of 7zr.exe
7zr.exe needs only 7 seconds for a packed 4GB file, Purebasic needs 67 seconds 
Here is an example code:
You can download a 1GB packed (538MB) test file HERE. (the packed file contains only hex characters)
The required 7zr.exe HERE, or directly from the manufacturer.
Here is a comparison with the console version of 7zr.exe
Code: Select all
FileSize: 538 MiB, unpack time:
PB: 18230 ms
7zr: 4215 ms
PureBasic is 333% slower
FileSize: 1076 MiB, unpack time:
PB: 31396 ms
7zr: 4921 ms
PureBasic is 538% slower
FileSize: 2128 MiB, unpack time:
PB: 67244 ms
7zr: 6961 ms
PureBasic is 866% slowerHere is an example code:
You can download a 1GB packed (538MB) test file HERE. (the packed file contains only hex characters)
The required 7zr.exe HERE, or directly from the manufacturer.
Code: Select all
EnableExplicit
UseLZMAPacker()
Procedure.q _unpackPB(Archiv.s)
Protected File.s, pt.q = ElapsedMilliseconds()
If OpenPack(0, Archiv, #PB_PackerPlugin_Lzma) And ExaminePack(0)
While NextPackEntry(0)
If PackEntryType(0) = #PB_Packer_File
File = GetTemporaryDirectory() + PackEntryName(0)
UncompressPackFile(0, File)
Break
EndIf
Wend
ClosePack(0)
EndIf
pt = ElapsedMilliseconds() - pt
If FileSize(File)
DeleteFile(File)
EndIf
ProcedureReturn pt
EndProcedure
Procedure.q _unpack7z(Archiv.s)
Protected Dir.s = GetTemporaryDirectory() + "~bin", pt.q = ElapsedMilliseconds()
RunProgram("7zr.exe", ReplaceString("x -aoa '"+Archiv+"' -o'"+Dir+"'", "'", #DQUOTE$), "", #PB_Program_Hide|#PB_Program_Wait)
pt = ElapsedMilliseconds() - pt
If FileSize(Dir) = -2
DeleteDirectory(Dir, "")
EndIf
ProcedureReturn pt
EndProcedure
Structure tTEST
File.s
PureBasic.q
SevenZip.q
EndStructure
If FileSize("7zr.exe") = -1
MessageRequester("", "pls, download 7zr.exe first!")
End
EndIf
Define Str.s, Diff.d, NewList Test.tTEST()
AddElement(Test()): Test()\File = "bin.7z"
ForEach Test(): With Test()
If FileSize(\File) > 0
\PureBasic = _unpackPB(\File)
\SevenZip = _unpack7z(\File)
Str = "FileSize: " + Str(FileSize(\File)/1024/1024) + ~" MiB, unpack time:\n" +
" PB: " + RSet(Str(\PureBasic), 5)+ ~" ms\n" +
" 7zr: " + RSet(Str(\SevenZip), 5) + ~" ms\n"
Diff = \PureBasic / \SevenZip * 100 - 100
If Diff > 0
Str + "PureBasic is " + StrD(Diff, 0) + ~"% slower\n"
Else
Str + "PureBasis is faster!\n"
EndIf
Else
Str = "file '" + \File + "' not found!"
EndIf
CompilerIf #PB_Compiler_Debugger
Debug Str
CompilerElse
MessageRequester("Unpack speed", Str)
CompilerEndIf
EndWith:Next