Why is the Registry provider so slow compared to .NET?


i'm working on script queries bunch of registry keys. had been using test-path registry provider, noticed seemed slow. swapped commands static method calls microsoft.win32.registry class. difference in speed full order of magnitude, two.

here's short piece of code bunch of iterations of both types of calls , averages results:

  $sumpsh = 0.0  $sumnet = 0.0  $maxcount = 10000  $regpath = 'hkey_local_machine\software\microsoft\windows\currentversion'    foreach ($i in 1..$maxcount)  {    $xpsh = (measure-command { test-path $regpath }).totalmilliseconds    $sumpsh += $xpsh        $xnet = (measure-command { [microsoft.win32.registry]::getvalue($regpath, [string]::empty, [string]::empty) }).totalmilliseconds    $sumnet += $xnet  }    "average powershell: $($sumpsh / $maxcount) milliseconds."  "average .net:    $($sumnet / $maxcount) milliseconds."  

here typical results on system (windows 7 enterprise 64-bit, intel core 2 duo 3.0 ghz, 8 gb of ram):

average powershell: 0.438589789999999 milliseconds.
average .net:         0.0493290700000029 milliseconds.

ideas why calling .net directly ten times faster using powershell registry provider?

thanks,
chuck

ok, forget sample code included in post. original program using test-path query registry keys, take around minute process 40 keys. when replaced calls test-path .net method calls, program finished instantly. don't see how caching cause in instance, registry keys being tested unique.


there's no magic reason. powershell just... slow. there's awful lot of plumbing around providers introduces the bottleneck you're seeing. powershell interpreted language slows down. thankfully there's more 1 way skin cat, have found.

-oisin



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group