Understanding the difference between running the built-in time counter and a time counter outside the code

OK The name of this qiestion is not just deciphered, but let me explain to you.

To establish a common language, I am going to provide some detailed information, but this question is intended to apply to all possible contexts, languages, and platforms.

Platform: .NET Framework 4.0 System: Windows (obviously) Language: F #

I need to run the program and evaluate the time taken to complete some instructions. Think that you have the main function: there you set the time counter:

open System.Diagnostics
let main args =
   let watch = new Stopwatch ()
   watch.Start ()
   (* Calling functions and executing main body... *)
   watch.Stop ()
   (* Printing out the evaluated time *)

OK! I get time and I'm happy.

Now I want to measure this time, but evaluating it from the outside. Therefore, consider a PowerShell script that runs a file, but also counts the time:

$MyProcess = New-Object "System.Diagnostics.Process";
$Watch = New-Object "System.Diagnostics.Stopwatch";
$MyProcess.StartInfo.FileName = "Myexec";
$MyProcess.StartInfo.Arguments = "args";
$MyProcess.StartInfo.CreateNoWindow = $true;
$MyProcess.StartInfo.UseShellExecute = $false;
$StartingTimer = $Watch.Start(); # Starts the timer
$StartingProcess = $MyProcess.Start();
$WaitingForExit = $MyProcess.WaitForExit();
$StoppingTimer = $Watch.Stop(); # Stops the timer
# Collectiong timings
$Ticks = $Watch.ElapsedTicks;
# Returning and printing
Write-Output "$Ticks";

. : , : in-code out-code. , ! , , . , ..... , cpu , , ...

? ?

+3
2
+5

Powershell ,

  (get-process -ID $PID).cpu

.

script. script, , - , , , .

+1

Source: https://habr.com/ru/post/1796628/


All Articles