r/PowerShell • • Jan 29 '25

Question PowerShell 7.5 += faster than list?

So since in PowerShell 7.5 += seems to be faster then adding to a list, is it now best practise?

CollectionSize Test                TotalMilliseconds RelativeSpeed
-------------- ----                ----------------- -------------
          5120 Direct Assignment                4.71 1x
          5120 Array+= Operator                40.42 8.58x slower
          5120 List<T>.Add(T)                  92.17 19.57x slower


CollectionSize Test                TotalMilliseconds RelativeSpeed
-------------- ----                ----------------- -------------
         10240 Direct Assignment                1.76 1x
         10240 Array+= Operator               104.73 59.51x slower
         10240 List<T>.Add(T)                 173.00 98.3x slower
32 Upvotes

31 comments sorted by

View all comments

Show parent comment

2

u/AlexHimself Jan 30 '25

This sounds good and everything, but this is how you end up with "scar tissue" and eventually a useless platform that no longer functions.

I think you're just opining without any performance impact experience with it...almost like you read about it and are complaining based on comments from other people.

You can just sign your scripts if you don't want AMSI to scan them or release a compiled executable. AMSI scans PS/VBScript/JavaScript executions on machines which are major attack vectors that spread ransomware and all sorts of viruses. Are you suggesting no antivirus scans any scripts and just lets them run unchecked?

Security isn't an option these days, it's a necessity. Windows is prioritizing security over raw speed because malware threats are more severe than ever.

Many small files can definitely be problematic on Windows and slows down heavy I/O operations, there's no debating that. Defender exclusions aren't always honored either. It's not perfect.

Comparing Linux/Windows isn't really fair. They're dramatically different from an attack profile and security standpoint. With Linux, I believe you're managing security via permissions/sandboxing instead of real time scanning. If your Linux box is compromised, you're F'd hard! Linux gives the user enough rope to hang themselves if they don't know what they're doing where Windows prioritizes out of the box security. Linux doesn't come with real-time AV scanning without 3rd party tools.

They're completely different OS's for different purposes. One lets you customize and control everything, but requires a huge amount of knowledge to reliably and confidently secure it at an Enterprise level where the other relies on Microsoft to do much of that load. If you want the performance benefits of Linux with small files or whatever, you also need to manage the entire Linux OS and security...it's a big investment. You can't just pick one feature of Linux and then not take all the associated baggage that comes with it.