Last active
March 17, 2018 20:22
-
-
Save guitarrapc/f8c0eed3830385d478ad058f5785ed56 to your computer and use it in GitHub Desktop.
Serial? PSJob? C# Async?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async Task Main() | |
{ | |
var client = new HttpClient(); | |
await Task.WhenAll(Enumerable.Range(0, 100).Select(x => client.GetStringAsync("https://google.com"))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Measure-Command {$job = 1..100 | %{Invoke-RestMethod -Method Get -Uri https://google.com &}; Receive-Job $job} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Measure-Command {1..100 | %{Invoke-RestMethod -Method Get -Uri https://google.com}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$csharp = "using System.Linq; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
public class AsyncRestMethod | |
{ | |
public static HttpClient client = new HttpClient(); | |
public static async Task<string[]> GetStringAsync(string uri, int count) { | |
return await Task.WhenAll(Enumerable.Range(0, count).Select(x => client.GetStringAsync(uri))); | |
} | |
} | |
" | |
Add-Type -TypeDefinition $csharp -Language CSharp | |
Measure-Command {[AsyncRestMethod]::GetStringAsync("https://google.com", 100).Result;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShellSerial.ps1 | |
TotalSeconds : 25.7549936 | |
# PowerShellJob.ps1 | |
TotalSeconds : 15.8745210 | |
# PowerShellWithCSharpAsyncTask.ps1 | |
TotalSeconds : 0.6443892 | |
# CSharpAsyncAwait.cs | |
00:00:00.97544477 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment