Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure the build execution time?

I am having build script in msbuild which will be invoked by powershell.

Build log file would look like this.

Build started 12/19/2011 2:01:54 PM.

Build succeeded. 0 Warning(s) 0 Error(s)

Time Elapsed 00:00:00.28

At starting point it will specify the build execution initiated time and the end it will say Time elapsed.

I would like to find the execution time using powershell or msbuild. How can i add all the time elapsed value or find the difference between last build started occurrence with first build occurrence?

As it is in log file , i don't know how to retrieve this and measure.

like image 950
Samselvaprabu Avatar asked Dec 22 '22 04:12

Samselvaprabu


2 Answers

Notice that if you use Measure-Command { }, it will consume the console output of your build. So any output would be gone.

A less intrusive way of doing this is by simply doing a subtraction of Get-Date values. For example, here would be your build.ps1 script:

$before = Get-Date
<your build command line>
$after = Get-Date

$time = $after - $before
$buildTime = "`nBuild finished in ";
if ($time.Minutes -gt 0)
{
    $buildTime += "{0} minute(s) " -f $time.Minutes;
}

$buildTime += "{0} second(s)" -f $time.Seconds;
like image 110
supermem613 Avatar answered Jan 13 '23 13:01

supermem613


Use Measure-Commmand to see how long is your build process. Here's an example:

Measure-Command { ./build.ps1 }

The output on my machine was:

PS D:\> Measure-Command { ./build.ps1 }


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 6
Milliseconds      : 443
Ticks             : 64439301
TotalDays         : 7.45825243055556E-05
TotalHours        : 0.00178998058333333
TotalMinutes      : 0.107398835
TotalSeconds      : 6.4439301
TotalMilliseconds : 6443.9301
like image 38
Abbas Avatar answered Jan 13 '23 14:01

Abbas