The PowerShell 5.0 has features to support ZIP archives – Expand-Archive and Compress-Archive. They are very handy but what about performance?
During deployment we have to extract a ZIP archive, and I wrote a simple PowerShell script to measure a performance two different ways to extract ZIP archive. The first method is using native PowerShell command Expand-Archive; the second method is using ExtractToDirectory method from System.IO.Compression.Filesystem.
$measureExpand = Measure-Command { $ProgressPreference=’SilentlyContinue’ Expand-Archive $archivePath "$destinationFolder\TestExpand" -Force } $measureExpand $measureExtract = Measure-Command { Add-Type -assembly System.IO.Compression.Filesystem [io.compression.zipfile]::ExtractToDirectory($archivePath, "$destinationFolder\TestExtract") } $measureExtract
The results are the following for around 90MB archive (10 tries).
- First column – ZIP archive and destination folder are on the same disk
- Second column – ZIP archive and destination folder are on different disks
- With antivirus software, expand archive takes around 10 – 15 minutes
--- ExtractToDirectory 0:46 Expand-Archive 1:45 --- ExtractToDirectory 0:54 Expand-Archive 2:29 --- ExtractToDirectory 1:04 Expand-Archive 1:57 --- ExtractToDirectory 1:10 Expand-Archive 1:59 --- ExtractToDirectory 1:05 Expand-Archive 1:55 --- ExtractToDirectory 1:05 Expand-Archive 1:56 --- ExtractToDirectory 1:01 Expand-Archive 1:53 --- ExtractToDirectory 0:56 Expand-Archive 2:00 --- ExtractToDirectory 1:01 Expand-Archive 1:59 --- ExtractToDirectory 1:02 Expand-Archive 1:57
--- ExtractToDirectory 0:12 Expand-Archive 1:20 --- ExtractToDirectory 0:14 Expand-Archive 1:25 --- ExtractToDirectory 0:13 Expand-Archive 1:28 --- ExtractToDirectory 0:13 Expand-Archive 1:28 --- ExtractToDirectory 0:13 Expand-Archive 1:28 --- ExtractToDirectory 0:13 Expand-Archive 1:28 --- ExtractToDirectory 0:13 Expand-Archive 1:28 --- ExtractToDirectory 0:14 Expand-Archive 1:28 --- ExtractToDirectory 0:14 Expand-Archive 1:25 --- ExtractToDirectory 0:13 Expand-Archive 1:26
Conclusions
- ExtractToDirectory is much faster then Expand-Archive
- Antivirus software kills performance – it’s obvious, but we sometimes forget about things working in a background
- Extract from/to the same disk drive is a bad idea
How can I reproduce your test?
Here is script used by me for performance tests.
1 comment