-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine perf and api usage around file creation and code writer (#3519)
Fixes Azure/autorest.csharp#4530 Fixes #3361 Fixes #3367
- Loading branch information
Showing
65 changed files
with
4,120 additions
and
906 deletions.
There are no files selected for viewing
This file contains 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 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
37 changes: 37 additions & 0 deletions
37
packages/http-client-csharp/generator/Microsoft.Generator.CSharp/perf/CodeWriterBenchmark.cs
This file contains 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,37 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.Generator.CSharp.Input; | ||
using Microsoft.Generator.CSharp.Providers; | ||
|
||
namespace Microsoft.Generator.CSharp.Perf | ||
{ | ||
public class CodeWriterBenchmark | ||
{ | ||
private TypeProviderWriter _writer; | ||
|
||
public CodeWriterBenchmark() | ||
{ | ||
PluginHandler pluginHandler = new PluginHandler(); | ||
pluginHandler.LoadPlugin(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName, "Projects", "Model")); | ||
|
||
var properties = new[] | ||
{ | ||
new InputModelProperty("MyProperty", "myProperty", "The property of mine", new InputPrimitiveType(InputPrimitiveTypeKind.Int32, false), true, false, false) | ||
}; | ||
var inputModel = new InputModelType("MyModel", null, null, null, "Test model", InputModelTypeUsage.RoundTrip, properties, null, Array.Empty<InputModelType>(), null, null, null, false); | ||
var modelProvider = new ModelProvider(inputModel); | ||
_writer = new TypeProviderWriter(modelProvider); | ||
} | ||
|
||
[Benchmark] | ||
public void WriteModel() | ||
{ | ||
_writer.Write(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rp/generator/Microsoft.Generator.CSharp/perf/Microsoft.Generator.CSharp.Tests.Perf.csproj
This file contains 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,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" /> | ||
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Microsoft.Generator.CSharp.ClientModel\src\Microsoft.Generator.CSharp.ClientModel.csproj" /> | ||
<ProjectReference Include="..\src\Microsoft.Generator.CSharp.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Projects\Model\Configuration.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Projects\Model\tspCodeModel.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
41 changes: 41 additions & 0 deletions
41
packages/http-client-csharp/generator/Microsoft.Generator.CSharp/perf/Program.cs
This file contains 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,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Diagnosers; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Running; | ||
using Perfolizer.Horology; | ||
|
||
namespace Microsoft.Generator.CSharp.Perf; | ||
|
||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
// To see the list of benchmarks that can be run | ||
// dotnet run -c Release --framework net8.0 --list flat | ||
|
||
// To run a specific benchmark class | ||
// dotnet run -c Release --framework net8.0 --filter System.ClientModel.Tests.Internal.Perf.ResourceProviderDataModel* | ||
|
||
// To run a specific benchmark method | ||
// dotnet run -c Release --framework net8.0 --filter *ResourceProviderDataModel.Read_PublicInterface | ||
// or | ||
// dotnet run -c Release --framework net8.0 --filter System.ClientModel.Tests.Internal.Perf.ResourceProviderDataModel.Read_PublicInterface | ||
|
||
// To run a specific benchmark class and category | ||
// dotnet run -c Release --framework net8.0 --anyCategories PublicInterface --filter System.ClientModel.Tests.Internal.Perf.ResourceProviderDataModel* | ||
|
||
var config = ManualConfig.Create(DefaultConfig.Instance); | ||
config.Options = ConfigOptions.JoinSummary | ConfigOptions.StopOnFirstError; | ||
config = config.AddDiagnoser(MemoryDiagnoser.Default); | ||
config.AddJob(Job.Default | ||
.WithWarmupCount(1) | ||
.WithIterationTime(TimeInterval.FromMilliseconds(250)) | ||
.WithMinIterationCount(15) | ||
.WithMaxIterationCount(20) | ||
.AsDefault()); | ||
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...client-csharp/generator/Microsoft.Generator.CSharp/perf/Projects/Model/Configuration.json
This file contains 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,6 @@ | ||
{ | ||
"output-folder": ".", | ||
"namespace": "UnbrandedTypeSpec", | ||
"library-name": "UnbrandedTypeSpec", | ||
"use-model-reader-writer": true | ||
} |
Oops, something went wrong.