Wednesday, March 28, 2007 5:31:53 AM UTC #

This little gem may come in handy when you think you may need to do some performance tuning on your PowerShell script. I'll just let my brilliant script do all the talking:


function Help-PerformanceTuning
{
      #this function helps me when I feel the urge to
      #optimize for performance
      $max = 4000

      $
regexObjects = @()
     
for($i=0; $i -lt ($max-1); $i++)
      {
            $
regexObjects += [regex](Get-TwelveRandomCharacters)
      }
     
      echo
"Congratulations! You've created $max Regex objects! That's totally, ridiculously wasteful! Now get back to work!"     
}

It sure cures what's ailing me!

Astute readers may have noted that I call a "Get-TwelveRandomCharacters" function in there. Well, we should all be pleased to note that I further waste resources by instantiating twelve Random objects for each Regex object created! Let's do this:


function Get-TwelveRandomCharacters
{
      $chars = @()
     
for ($i=0; $i -lt 12; $i++)
      {
            $r = new-object Random
           
$
chars += [string][char][byte]($r.Next(1,26)+64)
      }

      [string]::Join("", $
chars)
}

Awesome!

Categories: PowerShell
Technorati:
Wednesday, March 28, 2007 5:31:53 AM UTC  #     |  Comments [0]  |  Trackback Tracked by:
"SharePoint Plus PowerShell: Working with wikis" (Peter Seale's weblog) [Trackback]
Name
E-mail
Home page

Comment (Some html is allowed: b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Syndication

Search
Posts on this page
Categories
Sites I visit regularly
About

Powered by: newtelligence dasBlog 2.2.8279.16125

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012, Peter Seale

Send mail to the author(s) E-mail



Sign In