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 "" -OutFile "" }
Seconds           : 52
Milliseconds      : 96

Measure-Command { (New-Object System.Net.WebClient).DownloadFile("","") }
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…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.