locked
Is it good or bad? RRS feed

  • Question

  • I often get myself creating this kind of complex solutions, and I have been wondering if it is good or bad (not on the reading aspect, but on the topic of eating too much resources from the server and/or causing locks/not removing allocated resource etc.):

    Here is my example:

    $lists = (Get-SPWebApplication $url | Get-SPSite -Limit All | ? {$_.URL -match $example} | Get-SPWeb -Limit All | % { $_.Lists }).Where({$_.TemplateFeatureId -eq "xxx-xxx-xxx" -and $_.Views.Count -ge 1})

    What are your opinions?

    Tuesday, November 29, 2016 3:42 AM

Answers

  • Hi Sushi

    In my opinion, pipelining is often better than foreach loop in terms of memory utilization but it also makes script slow. Garbage collector would ultimately collect all the unused objects. It all depends on the data set that you are expecting. 


    Thanks
    Mohit

    • Proposed as answer by croute1 Tuesday, November 29, 2016 1:56 PM
    • Marked as answer by Dr. Sushi Sunday, December 4, 2016 9:46 PM
    Tuesday, November 29, 2016 4:55 AM

All replies

  • Hi Sushi

    In my opinion, pipelining is often better than foreach loop in terms of memory utilization but it also makes script slow. Garbage collector would ultimately collect all the unused objects. It all depends on the data set that you are expecting. 


    Thanks
    Mohit

    • Proposed as answer by croute1 Tuesday, November 29, 2016 1:56 PM
    • Marked as answer by Dr. Sushi Sunday, December 4, 2016 9:46 PM
    Tuesday, November 29, 2016 4:55 AM
  • Thanks Mohit!

    Yes I knew this question would be a tough one to answer, it all depends on what is on the statement :)

    How can we determine and profile a good speed comparison for Pipelines vs ForEach/ForLoop?

    Wednesday, November 30, 2016 9:05 PM
  • its depend upon the situation.

    PowerShell does not pass raw text down the pipeline, PowerShell passes structured .NET data objects down the pipeline.  Which cause formatting issue and output really messy. you can read following blogs to understand it.

    PowerShell Pipeline Perversion

    Also check this


    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://krossfarm.com

    Wednesday, November 30, 2016 10:43 PM
  • Hi Sushi

    You can use Measure-Command to compare script speed execution. 


    Thanks
    Mohit

    Thursday, December 1, 2016 7:23 AM
  • your response was the most suitable for me, but all other answers were great, learned a lot here :)
    Sunday, December 4, 2016 9:46 PM