简体   繁体   中英

How to improve speed of debugging in powershell

I have a script processing a lot of data but when executed in a powershell shell it takes about 1 ~ 2 seconds to execute.

However if I go in ISE or VSC and put a breakpoint it takes the order of 10 to 20 minutes to reach the breakpoint, and the breakpoint is not even near the end of the script.

Is there a logical explanation to why I'm having performance that is a factor 1000 slower when debugging compared to just execution? Execution of scripts in ISE/VSC is also slower than just in a shell btw.

Any configuration I can do, things I should be aware off? Cause it's really unworkable to properly debug my code this way.

Actually it is even worse. You can put a breakpoint somewhere in an opened script in ISE and then go to console and check some absolutely silly loop with measure-command. You will see, it runs much slower than when you don't have a breakpoint, though this loop has absolutely nothing to do with the script.

Eg I have a script (any script!) opened in Powershell ISE and no breakpoint set. Then:

Then I run some command in the console-window of ISE:

PS C:\WINDOWS\system32> measure-command -Expression {$oDNs | foreach {if ($_ -like '*Reutlingen*') {$_}}}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 56
Ticks             : 563149
TotalDays         : 6,51792824074074E-07
TotalHours        : 1,56430277777778E-05
TotalMinutes      : 0,000938581666666667
TotalSeconds      : 0,0563149
TotalMilliseconds : 56,3149

Now I put the breakpoint somewhere in the script and run the command again:

PS C:\WINDOWS\system32> measure-command -Expression {$oDNs | foreach {if ($_ -like '*Reutlingen*') {$_}}}


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 6
Milliseconds      : 320
Ticks             : 63206455
TotalDays         : 7,3155619212963E-05
TotalHours        : 0,00175573486111111
TotalMinutes      : 0,105344091666667
TotalSeconds      : 6,3206455
TotalMilliseconds : 6320,6455

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM