Skip to content

Instantly share code, notes, and snippets.

@MarkTiedemann
Last active April 4, 2017 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkTiedemann/6ecfa5ce96476fd44b2b92b99c915c98 to your computer and use it in GitHub Desktop.
Save MarkTiedemann/6ecfa5ce96476fd44b2b92b99c915c98 to your computer and use it in GitHub Desktop.
Run jobs in parallel using Powershell
$code = {
param ($id)
$start = Get-Date
# your code here
Start-Sleep 1
$stop = Get-Date
$total = ($stop - $start).TotalMilliSeconds
"[$id] $total ms"
}
$jobs = @()
1..4 | % {
$jobs += Start-Job $code -ArgumentList $_
}
$jobs | Wait-Job | Out-Null
$jobs | Receive-Job
$jobs | Remove-Job
# Output:
# [1] 1004.0012 ms
# [2] 1004.0012 ms
# [3] 1004.0012 ms
# [4] 1003.9979 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment