Benchpress

Benchpress is a quick and easy benchmarking toolkit for PowerShell

It helps you write and manage simple comparative benchmarks. You can use this information to make your scripts more efficient.

For instance, here’s a quick Benchmark to determine if you should use Foreach statement or foreach object

Measure-Benchmark -Technique @{
    ForeachObject = { 1..100 | Foreach-Object { $_ } }
    ForeachStatement = { foreach ($n in 1..100) { $n }}
}

You can install Benchpress from the PowerShell Gallery:

Install-Module Benchpress -Scope CurrentUser -Force

Benchmark comes with a number of PowerShell Performance experiments.

Name Results
Best Way To Accumulate Pipeline Results (source) Best Way To Accumulate Pipeline Results (results)
Checking If A File Exists (source) Checking If A File Exists (results)
Comparing Command Lookup (source) Comparing Command Lookup (results)
Creating Property Bags (source) Creating Property Bags (results)
Different Ways To Iterate (source) Different Ways To Iterate (results)
Different Ways To Set Many Variables (source) Different Ways To Set Many Variables (results)
How Much Faster Is Piping To A ScriptBlock (source) How Much Faster Is Piping To A ScriptBlock (results)
How Much Faster Is Splatting (source) How Much Faster Is Splatting (results)
How Much Faster Is The Static Constructor (source) How Much Faster Is The Static Constructor (results)
Is Using Faster (source) Is Using Faster (results)
multithreading (source) multithreading (results)
Random Number Generation (source) Random Number Generation (results)
Should I Include The System Namespace (source) Should I Include The System Namespace (results)
ToString Or Not ToString (source) ToString Or Not ToString (results)
Ways To Hash A File (source) Ways To Hash A File (results)
What Is The Fastest Way To Concatenate (source) What Is The Fastest Way To Concatenate (results)
What Is The Fastest Way To Filter (source) What Is The Fastest Way To Filter (results)
What Is The Fastest Way To Get All Loaded Modules (source) What Is The Fastest Way To Get All Loaded Modules (results)
What Is The Fastest Way To Read A File (source) What Is The Fastest Way To Read A File (results)
What Is The Fastest Way To Sort (source) What Is The Fastest Way To Sort (results)
What Is The Quickest Way To Compare Types (source) What Is The Quickest Way To Compare Types (results)
Whats In A Quote (source) Whats In A Quote (results)
Which Random Is Faster (source) Which Random Is Faster (results)

You can run all these built-in benchmarks by running.

Checkpoint-Benchmark -ModuleName Benchpress