PowerShell v4, 144 bytes
$d=date;gjb|rjb
1..20|%{sajb{$x=date;sleep 3;((date)-$x).Ticks/1e7}>$null}
while(gjb -s "Running"){}(gjb|rcjb)-join'+'|iex
((date)-$d).Ticks/1e7
Sets $d
equal to Get-Date
, and clears out any existing job histories with Get-Job | Remove-Job
. We then loop 1..20|%{...}
and each iteration execute Start-Job
passing it the script block {$x=date;sleep 3;((date)-$x).ticks/1e7}
for the job (meaning each job will execute that script block). We pipe that output to >$null
in order to suppress the feedback (i.e., job name, status, etc.) that gets returned.
The script block sets $x
to Get-Date
, then Start-Sleep
for 3
seconds, then takes a new Get-Date
reading, subtracts $x
, gets the .Ticks
, and divides by 1e7
to get the seconds (with precision).
Back in the main thread, so long as any job is still -S
tatus "Running"
, we spin inside an empty while
loop. Once that's done, we Get-Job
to pull up objects for all the existing jobs, pipe those to Receive-Job
which will pull up the equivalent of STDOUT (i.e., what they output), -join
the results together with +
, and pipe it to iex
(Invoke-Expression
and similar to eval
). This will output the resultant sleep time plus overhead.
The final line is similar, in that it gets a new date, subtracts the original date stamp $d
, gets the .Ticks
, and divides by 1e7
to output the total execution time.
NB
OK, so this is a little bendy of the rules. Apparently on first execution, PowerShell needs to load a bunch of .NET assemblies from disk for the various thread operations as they're not loaded with the default shell profile. Subsequent executions, because the assemblies are already in memory, work fine. If you leave the shell window idle long enough, you'll get PowerShell's built-in garbage collection to come along and unload all those assemblies, causing the next execution to take a long time as it re-loads them. I'm not sure of a way around this.
You can see this in the execution times in the below runs. I started a fresh shell, navigated to my golfing directory, and executed the script. The first run was horrendous, but the second (executed immediately) worked fine. I then left the shell idle for a few minutes to let garbage collection come by, and then that run is again lengthy, but subsequent runs again work fine.
Example runs
Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.
PS H:\> c:
PS C:\> cd C:\Tools\Scripts\golfing
PS C:\Tools\Scripts\golfing> .\wait-a-minute.ps1
63.232359
67.8403415
PS C:\Tools\Scripts\golfing> .\wait-a-minute.ps1
61.0809705
8.8991164
PS C:\Tools\Scripts\golfing> .\wait-a-minute.ps1
62.5791712
67.3228933
PS C:\Tools\Scripts\golfing> .\wait-a-minute.ps1
61.1303589
8.5939405
PS C:\Tools\Scripts\golfing> .\wait-a-minute.ps1
61.3210352
8.6386886
PS C:\Tools\Scripts\golfing>