简体   繁体   English

如何提高powershell中的调试速度

[英]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.我有一个处理大量数据的脚本,但是在 powershell shell 中执行时,执行时间大约为 1 到 2

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.但是,如果我进入 ISE 或 VSC 并设置断点,则需要 10 到 20分钟才能到达断点,而且断点甚至不会接近脚本的结尾。

Is there a logical explanation to why I'm having performance that is a factor 1000 slower when debugging compared to just execution?是否有一个合乎逻辑的解释,为什么我的性能在调试时比仅执行时慢 1000 倍? Execution of scripts in ISE/VSC is also slower than just in a shell btw.顺便说一句,在 ISE/VSC 中执行脚本也比仅在 shell 中执行要慢。

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.您可以在 ISE 中打开的脚本中放置一个断点,然后转到控制台并使用测量命令检查一些绝对愚蠢的循环。 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.例如,我在 Powershell ISE 中打开了一个脚本(任何脚本!)并且没有设置断点。 Then:然后:

Then I run some command in the console-window of ISE:然后我在 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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