开发者

Loading powershell script around 10000 times

开发者 https://www.devze.com 2023-01-09 14:37 出处:网络
I have a powershell script that runs during an msbuild process and validates some stuff by extracting info from log files.

I have a powershell script that runs during an msbuild process and validates some stuff by extracting info from log files. The script loads 2 xml files and then does some validation from the data extracted from the log files. Usually the script takes on average 1 to 2 seconds to ru开发者_如何学Pythonn. Loading the xml files takes around 800ms to run. Since the script runs 10000 times, it will load these xml files every single time and adding an overhead of loading time of 10000 * .8 sec = 8000 sec.

Is there a way to load these xml files once and then let the script use them for the 10000 times? Urgent help needed.


Don't know if it's possible in your situation, but when your project has 10.000 components, perhaps the powershell script could extract the component names and locations from the .csproj files and loop over them by itself. Would not only save you the time for loading the XML files over and over again, but also the time for loading the powershell environment 10000 times.


I think you have two choices:

1) Use something besides XML. A plain text file can be parsed much faster for simple key/value pairs, if you don't need the much richer data description of XML.

2) Refactor your build process such that PowerShell controls the MSBUILD for each of the 10,000 components. You can load those XML files at the beginning and reference them as necessary in any of the steps.


Assumming you have a powershell script that starts like

params([string]$docPath)

$xdoc = [xml] (get-content $docPath)
// do stuff w/ $xdoc

change it to

params([xml]$xdoc)
// do stuff w/ $xdoc 
0

精彩评论

暂无评论...
验证码 换一张
取 消