-
Notifications
You must be signed in to change notification settings - Fork 98
Add benchmark tests for v3 (and v2) performance #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4a438cd
Update nuget client dependency packages
alerickson cdf2316
Merge branch 'master' of https://github.com/PowerShell/PowerShellGet
alerickson 3bac8d1
Merge branch 'master' of https://github.com/PowerShell/PowerShellGet
alerickson e4f9e27
Merge branch 'master' of https://github.com/PowerShell/PowerShellGet
alerickson a021992
Add benchmark project
alerickson a633df8
target netstandard2.0
alerickson e4d179f
Update target framework and get 'run' working
alerickson da816e9
Finish writing tests for remote repositories
alerickson d7714b1
Add tests for local repositories
alerickson dd65b68
Add readme
alerickson 53b242c
Change 'benchmark' to 'Benchmark'
alerickson 93b0650
Minor fixes, move internals visible to csproj
alerickson c2151a0
Clean up tests
alerickson 800f8ba
Add new line to program.cs file
alerickson fe67078
Update test/perf/benchmarks/BenchmarksV2LocalRepo.cs
alerickson ac8a03d
Update test/perf/benchmarks/BenchmarksV2LocalRepo.cs
alerickson ecad5d7
Update test/perf/benchmarks/BenchmarksV2LocalRepo.cs
alerickson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.PowerShell; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Management.Automation; | ||
|
||
namespace Benchmarks | ||
{ | ||
public class BenchmarksV2LocalRepo | ||
{ | ||
System.Management.Automation.PowerShell pwsh; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
// Setting up the PowerShell runspace | ||
var defaultSS = System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2(); | ||
defaultSS.ExecutionPolicy = ExecutionPolicy.Unrestricted; | ||
pwsh = System.Management.Automation.PowerShell.Create(defaultSS); | ||
|
||
// Using PSGet v3 in order to save the Az modules and its dependencies | ||
pwsh.AddScript("Import-Module PowerShellGet -RequiredVersion 3.0.14 -Force"); | ||
pwsh.AddScript("New-Item TestRepo -ItemType Directory"); | ||
pwsh.AddScript("Save-PSResource -Name Az -Repository PSGallery -AsNupkg -TrustRepository -Path .\\TestRepo"); | ||
|
||
// Now import the PSGet module version we want to test and register a local repo | ||
pwsh.AddScript("Import-Module PowerShellGet -RequiredVersion 2.2.5 -Force"); | ||
pwsh.AddScript("Register-PSRepository -Name LocalRepo -SourceLocation .\\TestRepo"); | ||
|
||
pwsh.Invoke(); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
{ | ||
pwsh.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleV2() | ||
|
||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-Module -Name Az -Repository LocalRepo"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleAndDependenciesV2() | ||
|
||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-Module -Name Az -IncludeDependencies -Repository LocalRepo"); | ||
alerickson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void InstallAzModuleAndDependenciesV2() | ||
|
||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Install-Module -Name Az -Repository LocalRepo -Force"); | ||
alerickson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pwsh.Invoke(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.PowerShell; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Management.Automation; | ||
|
||
namespace Benchmarks | ||
{ | ||
public class BenchmarksV2RemoteRepo | ||
{ | ||
System.Management.Automation.PowerShell pwsh; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
// Setting up the PowerShell runspace | ||
var defaultSS = System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2(); | ||
defaultSS.ExecutionPolicy = ExecutionPolicy.Unrestricted; | ||
pwsh = System.Management.Automation.PowerShell.Create(defaultSS); | ||
|
||
// Import the PSGet version we want to test | ||
pwsh.AddScript("Import-Module PowerShellGet -RequiredVersion 2.2.5 -Force"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[GloblaCleanup] | ||
public void IterationCleanup() | ||
{ | ||
pwsh.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleV2() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-Module -Name Az -Repository PSGallery"); | ||
alerickson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleAndDependenciesV2() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-Module -Name Az -IncludeDependencies -Repository PSGallery"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void InstallAzModuleAndDependenciesV2() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Install-Module -Name Az -Repository PSGallery -Force"); | ||
pwsh.Invoke(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.PowerShell; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Management.Automation; | ||
|
||
namespace Benchmarks | ||
{ | ||
public class BenchmarksV3LocalRepo | ||
{ | ||
System.Management.Automation.PowerShell pwsh; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
// Setting up the PowerShell runspace | ||
var defaultSS = System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2(); | ||
defaultSS.ExecutionPolicy = ExecutionPolicy.Unrestricted; | ||
pwsh = System.Management.Automation.PowerShell.Create(defaultSS); | ||
|
||
// Import the PSGet module version we want to test, register a local repo, and save the Az modules and its dependencies | ||
pwsh.AddScript("Import-Module PowerShellGet -RequiredVersion 3.0.14 -Force"); | ||
pwsh.AddScript("New-Item TestRepo -ItemType Directory"); | ||
pwsh.AddScript("Register-PSResourceRepository -Name LocalRepo -Uri .\\TestRepo"); | ||
pwsh.AddScript("Save-PSResource -Name Az -Repository PSGallery -AsNupkg -TrustRepository -Path .\\TestRepo"); | ||
|
||
pwsh.Invoke(); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
{ | ||
pwsh.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-PSResource -Name Az -Repository LocalRepo"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleAndDependenciesV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-PSResource -Name Az -IncludeDependencies -Repository LocalRepo"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void InstallAzModuleV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Install-PSResource -Name Az -Repository LocalRepo -TrustRepository -SkipDependencyCheck -Reinstall"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void InstallAzModuleAndDependenciesV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Install-PSResource -Name Az -Repository LocalRepo -TrustRepository -Reinstall"); | ||
pwsh.Invoke(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.PowerShell; | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Management.Automation; | ||
|
||
namespace Benchmarks | ||
{ | ||
public class BenchmarksV3RemoteRepo | ||
{ | ||
System.Management.Automation.PowerShell pwsh; | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
// Setting up the PowerShell runspace | ||
var defaultSS = System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2(); | ||
defaultSS.ExecutionPolicy = ExecutionPolicy.Unrestricted; | ||
pwsh = System.Management.Automation.PowerShell.Create(defaultSS); | ||
|
||
// Import the PSGet version we want to test | ||
pwsh.AddScript("Import-Module PowerShellGet -RequiredVersion 3.0.14 -Force"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
{ | ||
pwsh.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-PSResource -Name Az -Repository PSGallery"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void FindAzModuleAndDependenciesV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Find-PSResource -Name Az -IncludeDependencies -Repository PSGallery"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void InstallAzModuleV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Install-PSResource -Name Az -Repository PSGallery -TrustRepository -SkipDependencyCheck -Reinstall"); | ||
pwsh.Invoke(); | ||
} | ||
|
||
[Benchmark] | ||
public void InstallAzModuleAndDependenciesV3() | ||
{ | ||
pwsh.Commands.Clear(); | ||
pwsh.AddScript("Install-PSResource -Name Az -Repository PSGallery -TrustRepository -Reinstall"); | ||
pwsh.Invoke(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet.Running; | ||
|
||
namespace Benchmarks | ||
{ | ||
public sealed class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var summaryV2Remote = BenchmarkRunner.Run<BenchmarksV2RemoteRepo>(); | ||
var summaryV3Remote = BenchmarkRunner.Run<BenchmarksV3RemoteRepo>(); | ||
var summaryV2Local = BenchmarkRunner.Run<BenchmarksV2LocalRepo>(); | ||
var summaryV3Local = BenchmarkRunner.Run<BenchmarksV3LocalRepo>(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Micro Benchmarks | ||
|
||
This folder contains micro benchmarks that test the performance of PowerShellGet. | ||
|
||
### Quick Start | ||
|
||
You can run the benchmarks directly using `dotnet run` in this directory: | ||
1. To run the benchmarks in Interactive Mode, where you will be asked which benchmark(s) to run: | ||
``` | ||
dotnet run -c Release -f net6.0 | ||
``` | ||
|
||
2. To list all available benchmarks ([read more](https://github.com/dotnet/performance/blob/main/docs/benchmarkdotnet.md#Listing-the-Benchmarks)): | ||
``` | ||
dotnet run -c Release -f net6.0 --list [flat/tree] | ||
``` | ||
|
||
3. To filter the benchmarks using a glob pattern applied to `namespace.typeName.methodName` ([read more](https://github.com/dotnet/performance/blob/main/docs/benchmarkdotnet.md#Filtering-the-Benchmarks)]): | ||
``` | ||
dotnet run -c Release -f net6.0 --filter *script* --list flat | ||
``` | ||
|
||
4. To profile the benchmarked code and produce an ETW Trace file ([read more](https://github.com/dotnet/performance/blob/main/docs/benchmarkdotnet.md#Profiling)) | ||
``` | ||
dotnet run -c Release -f net6.0 --filter *script* --profiler ETW | ||
``` | ||
|
||
## References | ||
|
||
- [Getting started with BenchmarkDotNet](https://benchmarkdotnet.org/articles/guides/getting-started.html) | ||
- [Micro-benchmark Design Guidelines](https://github.com/dotnet/performance/blob/main/docs/microbenchmark-design-guidelines.md) | ||
- [Adam SITNIK: Powerful benchmarking in .NET](https://www.youtube.com/watch?v=pdcrSG4tOLI&t=351s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<DebugSymbols>true</DebugSymbols> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Optimize>true</Optimize> | ||
<Configuration>Release</Configuration> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../../src/code/PowerShellGet.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" /> | ||
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.1"/> | ||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.5" /> | ||
</ItemGroup> | ||
</Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.