Skip to content

Invoke-WebRequest vs System.Net.WebClient Download Speed

I was doing some PowerShell scripts at work and I was typically using Invoke-WebRequest to download files as it’s the simplest method to do so. But after some testing and playing I started thinking “wow this is pretty slow…”

I did some googling and I only found a few forums where someone said “Invoke-WebRequest is slow” in fact my Google-Fu is pretty good and I was having a hard time finding related information. Even now I’m unaware of a way to make Invoke-WebRequest download a file even remotely as quick as System.Net.WebClient…

But here take a look at this which I just now executed:

Measure-Command { Invoke-WebRequest "http://download.thinkbroadband.com/100MB.zip" -OutFile "C:temptest1.zip" }
Seconds           : 52
Milliseconds      : 96

Measure-Command { (New-Object System.Net.WebClient).DownloadFile("http://download.thinkbroadband.com/200MB.zip","c:temptest2.zip") }
Seconds           : 35
Milliseconds      : 444

In case you missed it, that’s a 100MB download in 52 seconds vs a 200MB download in 35 seconds…in my tests at work Invoke-WebRequest was taking nearly 3 minutes to download a 400MB file over our CDN where as System.Net.WebClient was taking about 8 seconds…~3MB/s vs ~50MB/s

I have a local webserver at home, downloading a 700MB file:

Measure-Command { (New-Object System.Net.WebClient).DownloadFile('http://plex:32400/library/parts/20577/file.mp4?stripTags=0',"c:temptest.mp4") }
Seconds           : 14
Milliseconds      : 873
Measure-Command { Invoke-WebRequest "http://plex:32400/library/parts/20577/file.mp4?stripTags=0" -OutFile "C:temptest2.mp4" }
Seconds           : 44
Milliseconds      : 322

As you can see System.Net.WebClient should be the preferred method for downloading large files…

Published inTech

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *