Skip to content

Instantly share code, notes, and snippets.

@alkampfergit
Last active August 10, 2021 14:49
Show Gist options
  • Save alkampfergit/0a6b683f3e9bb1b63a43c75c94abe5a8 to your computer and use it in GitHub Desktop.
Save alkampfergit/0a6b683f3e9bb1b63a43c75c94abe5a8 to your computer and use it in GitHub Desktop.
PowerShell 7zip timing
$sizeInBytes = 859236677
function Dump-Execution(
[string] $fileName,
[int] $elapsed,
[int] $referenceTime,
[int] $referenceSize,
[string] $description
)
{
$compressedFile = Get-Item $fileName
$compressedSize = $compressedFile.Length
$reductionInSize = $compressedSize * 100 / $sizeInBytes
$increaseInCompressionTime = $elapsed * 100 / $referenceTime
$relativeCompressionSize = $compressedSize * 100 / $referenceSize
$dumpString = "$description-> $elapsed ms file size $compressedSize global reduction of {0:00.0}% relative increase in compression time {1:00.0}% vs relative reduction {2:00.0}%" -f $reductionInSize, $increaseInCompressionTime, $relativeCompressionSize
Write-Host $dumpString
}
$sourceDir = "C:\temp\testrelease\fullfw\*"
$destinationDir = "C:\temp\testrelease\out"
Set-Alias sz "C:\Program Files\7-Zip\7z.exe"
Set-Alias sza "C:\Program Files\7-Zip\7za\7za.exe"
Set-Alias sza920 "C:\Program Files\7-Zip\7za920\7za.exe"
if (Test-Path $destinationDir)
{
Remove-Item $destinationDir -Recurse
}
$filePrefix = ""
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=1 "$destinationDir\test_$filePrefix_1.7z" $sourceDir > $null
$reference = $sw.ElapsedMilliseconds
$referenceSize = (Get-Item "$destinationDir\test_$filePrefix_1.7z").Length
Dump-Execution -fileName "$destinationDir\test_$filePrefix_1.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=1" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=3 "$destinationDir\test_$filePrefix_3.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_3.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=3" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=5 "$destinationDir\test_$filePrefix_5.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_5.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=5" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=7 "$destinationDir\test_$filePrefix_7.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_7.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=7" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=9 "$destinationDir\test_$filePrefix_9.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_9.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=9" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=1 -mqs=on "$destinationDir\test_$filePrefix_1.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_1.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=1 -mqs=on" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=3 -mqs=on "$destinationDir\test_$filePrefix_3.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_3.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=3 -mqs=on" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=5 -mqs=on "$destinationDir\test_$filePrefix_5.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_5.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=5 -mqs=on" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=7 -mqs=on "$destinationDir\test_$filePrefix_7.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_7.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=7 -mqs=on" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sz a -mx=9 -mqs=on "$destinationDir\test_$filePrefix_9.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test_$filePrefix_9.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=9 -mqs=on" -referenceTime $reference -referenceSize $referenceSize
# Now compress with old 7za version 9.20
$sw = [Diagnostics.Stopwatch]::StartNew()
sza920 a -mx=1 "$destinationDir\test7za920_1.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test7za920_1.7z" -elapsed $sw.ElapsedMilliseconds -description "7za920.exe mx=1" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sza920 a -mx=3 "$destinationDir\test7za920_3.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test7za920_3.7z" -elapsed $sw.ElapsedMilliseconds -description "7za920.exe mx=3" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sza920 a -mx=5 "$destinationDir\test7za920_5.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test7za920_5.7z" -elapsed $sw.ElapsedMilliseconds -description "7za920.exe mx=5" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sza920 a -mx=7 "$destinationDir\test7za920_7.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test7za920_7.7z" -elapsed $sw.ElapsedMilliseconds -description "7za920.exe mx=7" -referenceTime $reference -referenceSize $referenceSize
$sw = [Diagnostics.Stopwatch]::StartNew()
sza920 a -mx=9 "$destinationDir\test7za920_9.7z" $sourceDir > $null
Dump-Execution -fileName "$destinationDir\test7za920_9.7z" -elapsed $sw.ElapsedMilliseconds -description "7za920.exe mx=9" -referenceTime $reference -referenceSize $referenceSize
# sz a -mx=1 -mm=LZMA "$destinationDir\test1lzma.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test1lzma.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=1 LZMA" -referenceTime $reference -referenceSize $referenceSize
# sz a -mx=3 -mm=LZMA "$destinationDir\test3lzma.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test3lzma.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=3 LZMA" -referenceTime $reference -referenceSize $referenceSize
# sz a -mx=5 -mm=LZMA "$destinationDir\test5lzma.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test5lzma.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=5 LZMA" -referenceTime $reference -referenceSize $referenceSize
# sz a -mx=7 -mm=LZMA "$destinationDir\test7lzma.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test7lzma.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=7 LZMA" -referenceTime $reference -referenceSize $referenceSize
# sz a -mx=9 -mm=LZMA "$destinationDir\test9lzma.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test9lzma.7z" -elapsed $sw.ElapsedMilliseconds -description "mx=9 LZMA" -referenceTime $reference -referenceSize $referenceSize
# $sw = [Diagnostics.Stopwatch]::StartNew()
# sza a -mx=1 "$destinationDir\test7za1.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test7za1.7z" -elapsed $sw.ElapsedMilliseconds -description "7za.exe mx=1" -referenceTime $reference -referenceSize $referenceSize
#
# $sw = [Diagnostics.Stopwatch]::StartNew()
# sza a -mx=3 "$destinationDir\test7za3.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test7za3.7z" -elapsed $sw.ElapsedMilliseconds -description "7za.exe mx=3" -referenceTime $reference -referenceSize $referenceSize
#
# $sw = [Diagnostics.Stopwatch]::StartNew()
# sza a -mx=5 "$destinationDir\test7za5.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test7za5.7z" -elapsed $sw.ElapsedMilliseconds -description "7za.exe mx=5" -referenceTime $reference -referenceSize $referenceSize
#
# $sw = [Diagnostics.Stopwatch]::StartNew()
# sza a -mx=7 "$destinationDir\test7za7.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test7za7.7z" -elapsed $sw.ElapsedMilliseconds -description "7za.exe mx=7" -referenceTime $reference -referenceSize $referenceSize
#
# $sw = [Diagnostics.Stopwatch]::StartNew()
# sza a -mx=9 "$destinationDir\test7za9.7z" $sourceDir > $null
# Dump-Execution -fileName "$destinationDir\test7za9.7z" -elapsed $sw.ElapsedMilliseconds -description "7za.exe mx=9" -referenceTime $reference -referenceSize $referenceSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment