I am writing a PowerShell program to analyse the content of 1900+ big XML configuration files (50000+ lines, 1.5Mb). Just for test I move 36 test files to my PC (Win 10; PS 5.1; 32GB RAM) and write quick script to test the speed of execution.
$TestDir = "E:\Powershell\Test"
$TestXMLs = Get-ChildItem $TestDir -Recurse -Include *.xml
foreach ($TestXML in $TestXMLs)
{
[xml]$XML = Get-Content $TestXML
(($XML.root.servers.server).Where{$_.name -eq "Server1"}).serverid
}
That is completed for 36 to 40 seconds. I done several tests with measure-command.
Then I tried workflow with foreach -paralell assuming that parallel loading of several files will give me more faster process.
Workflow Test-WF
{
$TestDir = "E:\Powershell\Test"
$TestXMLs = Get-ChildItem $TestDir -Recurse -Include *.xml
foreach -parallel -throttle 10 ($TestXML in $TestXMLs)
{
[xml]$XML = Get-Content $TestXML
(($TestXML.root.servers.server).Where{$_.name -eq "Sevrver1"}).serverid
}
}
Test-WF #execute workflow
Script with the workflow needs between 118 and 132 seconds.
Now I am just wondering what could be the reason that workflow works so much slower? Recompiling to XMAL maybe or slower algorithm for loading XML files in WWF?