# How to measure execution time for background jobs?

**URL:** <https://forums.powershell.org/t/how-to-measure-execution-time-for-background-jobs/2081>\
**Category:** PowerShell Help\
**Created:** [November 16, 2013, 9:20pm UTC](https://forums.powershell.org/t/how-to-measure-execution-time-for-background-jobs/2081 "2013-11-16T21:20:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhay-patil](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@abhay-patil](https://forums.powershell.org/u/abhay-patil)\
**Post date:** [November 16, 2013, 9:20pm UTC](https://forums.powershell.org/t/how-to-measure-execution-time-for-background-jobs/2081/1 "2013-11-16T21:20:18Z")

</div>

I would like to compare my script execution performance with and without running background jobs.  
Measure-command snippets provide required data for script without running jobs,

Is there any snippet available for measuring background job performance.

Thanks  
Abhay

---

<div class="post-metadata">

**Author:** ![chris-stephens](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@chris-stephens](https://forums.powershell.org/u/chris-stephens)\
**Post date:** [November 17, 2013, 11:09am UTC](https://forums.powershell.org/t/how-to-measure-execution-time-for-background-jobs/2081/2 "2013-11-17T11:09:23Z")

</div>

Perhaps you could encapsulate the Measure-Command scriptblock to include the following expression:

1. Start-Job.
2. Loop that waits 1 second and does Get-Job to see if it’s running.
3. When it is not running, exit the loop and finish the script.

I think that would work for you.

---

<div class="post-metadata">

**Author:** ![jonathanweinberg](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jonathanweinberg](https://forums.powershell.org/u/jonathanweinberg)\
**Post date:** [May 26, 2016, 3:43pm UTC](https://forums.powershell.org/t/how-to-measure-execution-time-for-background-jobs/2081/3 "2016-05-26T15:43:46Z")

</div>

So, I’m very sorry to revive this very old thread, but several Google searches let me here.

Here’s what I figured out, about trying to measure background job performance.

It’s actually stored as part of the job!

Here’s what I did:  
Ran a job. It showed up as “Job1”.  
When it was complete, I ran:

```
((Get-Job Job1).PSEndTime.TimeOfDay - (Get-Job Job1).PSBeginTime.TimeOfDay).TotalMinutes
```

To explore what else is available, use Get-Member. So run:

```
((Get-Job Job1).PSBeginTime.TimeOfDay) | Get-Member
```

Hope this helps someone!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:41pm UTC](https://forums.powershell.org/t/how-to-measure-execution-time-for-background-jobs/2081/4 "2024-05-16T20:41:08Z")

</div>


