These are: ZIP, LZMA, BriefLZ, TAR.GZip, and TAR.BZip2 (ps. Fred it would be nice if BZIP2 and GZIP were available on their own, rather than having to use TAR bundling! TAR is ewww but BZIP2 is awesome!)
So here's a simple test program to help find out which of Purebasic's built-in packers is best suited to the data we want to compress/decompress.
The variables are PACK TIME, UNPACK TIME, PACK SIZE/RATIO, and PB EXE SIZE. Each packer of course has its own strengths and weaknesses!
Here's the results of a 91 megabyte SQL dump (UTF8 textfile). Tested with Purebasic x86 5.40 LTS in Windows XP. I havent had a chance to do x64 test.
I ran each test twice and only recorded the 2nd result to ensure 'even caching':
Code: Select all
ZIP LZMA BriefLZ TAR TAR.GZ TAR.BZ2 "Winning" order (TAR excluded):
-------------------------------------------------------------- ----------------
PACK TIME 3175ms 67647ms 1653ms 1141ms 3325ms 9464ms BriefLZ, ZIP, TAR.GZ, TAR.BZ2, LZMA
UNPACK TIME 1532ms 2254ms 2273ms 1252ms 1332ms 3145ms TAR.GZ, ZIP, LZMA, BriefLZ, TAR.BZ2
PACK SIZE 25218579 18887882 34247532 94030848 25218522 19782588
PACK RATIO 26.820% 20.087% 36.422% 100.002% 26.820% 21.039% LZMA, TAR.BZ2, TAR.GZ, ZIP, BriefLZ
PB.EXE SIZE 207,872 291,328 15,872 219,648 219,648 219,648 BriefLZ, ZIP, TAR.GZ/TAR.BZ2, LZMA
ZIP: A great balance of compression and speed.
LZMA: Extremely slow compression, but thats the price you pay for the very best compression ratio.
BriefLZ: Extremely good performance in both packing & unpacking, and the resulting exe is still TINY unlike the others. 36% compression to ZIPs 26% means it's not great, but still pretty good.
TAR.GZ: On par with ZIP.
TAR.BZ2: Compression ratio so very close to LZMA yet compression speed is 7x faster. Decompression 1.4x slower than LZMA however.
Quite a nice menu to choose from, depending on ours projects individual needs

One of the nice surprises I found was that the BriefLZ codec only adds 10kb to the exe - thats with full compress + decompress support! And its speed of both is very good, especially compression but still respectable decompress speed. Its compression ratio is also quite respectable too, compressing my 91mb sample file to 36%. Compared to ZIPs 27% its not great but still pretty good, and overall I think it makes an excellent packer for executable resources!
Code: Select all
#PACKER = 1 ;1=ZIP 2=LZMA 3=BriefLZ 4=TAR 5=TAR.GZ 6=TAR.BZ2
sFileToPack.s = "c:\temp\91mb.txt" ;Test file to compress. Ensure you have write access to c:\temp\
sFileToSave.s = "c:\temp\mytemparchive" ;Save to this archive file (minus extension)
CompilerIf #PB_Compiler_Debugger = 1
MessageRequester("Disable the debugger first", "Error": End ;in future ill use CompilerError
CompilerEndIf
CompilerIf #PACKER = 1
UseZipPacker()
sSaveFile.s = sFileToSave + ".zip"
PackerId = #PB_PackerPlugin_Zip
sResult.s = "Packer: ZIP" + #CRLF$
CompilerElseIf #PACKER = 2
UseLZMAPacker()
sSaveFile.s = sFileToSave + ".lzma"
PackerId = #PB_PackerPlugin_Lzma
sResult.s = "Packer: LZMA" + #CRLF$
CompilerElseIf #PACKER = 3
UseBriefLZPacker()
sSaveFile.s = sFileToSave + ".brieflz"
PackerId = #PB_PackerPlugin_BriefLZ
sResult.s = "Packer: BriefLZ" + #CRLF$
CompilerElseIf #PACKER = 4
UseTARPacker()
sSaveFile.s = sFileToSave + ".tar"
PackerId = #PB_PackerPlugin_Tar
sResult.s = "Packer: TAR" + #CRLF$
CompilerElseIf #PACKER = 5
UseTARPacker()
sSaveFile.s = sFileToSave + ".tar.gz"
PackerId = #PB_PackerPlugin_Tar | #PB_Packer_Gzip
sResult.s = "Packer: TAR.GZ" + #CRLF$
CompilerElseIf #PACKER = 6
UseTARPacker()
sSaveFile.s = sFileToSave + ".tar.bz2"
PackerId = #PB_PackerPlugin_Tar | #PB_Packer_Bzip2
sResult.s = "Packer: TAR.BZ2" + #CRLF$
CompilerElse
MessageRequester("Invalid packer id","Error"): End
CompilerEndIf
DeleteFile(sSaveFile)
OrigSize.i = FileSize(sFileToPack)
hPack.i = CreatePack(#PB_Any, sSaveFile, PackerId)
If hPack = 0
MessageRequester("Error","CreatePack failed")
Else
Time1.i = GetTickCount_()
AddPackFile(hPack, sFileToPack, "packed.dat")
TimePack.i = GetTickCount_() - Time1
ClosePack(hPack)
hPack.i = OpenPack(#PB_Any, sSaveFile, PackerId)
If hPack = 0
MessageRequester("Error","OpenPack failed")
Else
DeleteFile("c:\~extract.dat")
Time1.i = GetTickCount_()
Result = ExaminePack(hPack)
NextPackEntry(hPack)
Unpacked.i = UncompressPackFile(hPack, "c:\~extract.dat")
TimeUnpack.i = GetTickCount_() - Time1
ClosePack(hPack)
EndIf
sResult = sResult + "Packed in " + Str(TimePack) + "ms" + #CRLF$ +
"Unpacked in " + Str(TimeUnpack) + "ms" + #CRLF$ +
"Packsize=" + Str(FileSize(sSaveFile)) + " (" + StrF((FileSize(sSaveFile)/ OrigSize) * 100,3) + "%)" + #CRLF$ +
"Origsize=" + Str(OrigSize) + " Unpacked=" + Str(Unpacked) + #CRLF$ +
"Executable size=" + Str(FileSize(ProgramFilename()))
MessageRequester("Result", sResult)
SetClipboardText(sResult)
EndIf