Skip to content
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

Add benchmarks #7963

Merged
merged 6 commits into from
Dec 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify
  • Loading branch information
chsienki committed Dec 2, 2022
commit b5fe2e5bfa6f72263954679365d00c8631134625
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using BenchmarkDotNet.Attributes;
using Microsoft.Build.Locator;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using static Microsoft.AspNetCore.Razor.Microbenchmarks.Generator.ProjectSetup;

namespace Microsoft.AspNetCore.Razor.Microbenchmarks.Generator;

Expand All @@ -24,14 +22,6 @@ public enum StartupKind { Warm, Cold };
[ParamsAllExceptDebug(StartupKind.Warm)]
public StartupKind Startup { get; set; }

public enum FileTypeKind { CSharp, Razor };
[ParamsAllExceptDebug(FileTypeKind.Razor)]
public FileTypeKind FileType { get; set; }

public enum OperationKind { AddFile, EditFile, RemoveFile };
[ParamsAllExceptDebug(OperationKind.EditFile)]
public OperationKind Operation { get; set; }

[ModuleInitializer]
public static void LoadMSBuild() => MSBuildLocator.RegisterDefaults();
333fred marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -46,14 +36,7 @@ public void RunBenchmark()
{
var compilation = _project!.Compilation;
var driver = _project!.GeneratorDriver;
if (FileType == FileTypeKind.CSharp)
{
compilation = CSharpChange();
}
else
{
driver = RazorChange();
}
driver = RazorChange();

driver = driver.RunGenerators(compilation);
var result = driver.GetRunResult();
Expand Down Expand Up @@ -87,64 +70,28 @@ private GeneratorDriver RazorChange()
{
if (Change == ChangeKind.Independent)
{
return new InMemoryAdditionalText(IndependentRazorFile, "Pages/Generated/0.razor");
return new ProjectSetup.InMemoryAdditionalText(IndependentRazorFile, "Pages/Generated/0.razor");
}
else if (Change == ChangeKind.DependentIgnorable)
{
return new InMemoryAdditionalText(DependentIgnorableRazorFile, "Pages/Counter.razor");
return new ProjectSetup.InMemoryAdditionalText(DependentIgnorableRazorFile, "Pages/Counter.razor");
}
else
{
return new InMemoryAdditionalText(DependentRazorFile, "Pages/Counter.razor");
return new ProjectSetup.InMemoryAdditionalText(DependentRazorFile, "Pages/Counter.razor");
}
}

private AdditionalText? GetExistingRazorFile()
{
if (Change != ChangeKind.Independent)
{
return _project!.AdditionalTexts.Single(a => a.Path.EndsWith("Counter.razor", StringComparison.OrdinalIgnoreCase));
}
else
{
return _project!.AdditionalTexts.Single(a => a.Path.EndsWith("0.razor", StringComparison.OrdinalIgnoreCase));
}
}

private Compilation CSharpChange()
{
var compilation = _project!.Compilation;
var newSyntaxTree = GetNewTree();
var existingSyntaxTree = GetExistingTree();

if (newSyntaxTree is not null)
{
compilation = compilation.AddSyntaxTrees(newSyntaxTree);
}
if (existingSyntaxTree is not null)
{
compilation = compilation.RemoveSyntaxTrees(existingSyntaxTree);
}

return compilation;
}

private SyntaxTree? GetNewTree()
{
if (Change == ChangeKind.Independent)
{
return CSharpSyntaxTree.ParseText("public class D{}", _project!.ParseOptions);
return _project!.AdditionalTexts.Single(a => a.Path.EndsWith("0.razor", StringComparison.OrdinalIgnoreCase));
}
return null;
}

private SyntaxTree? GetExistingTree()
{
if (Operation == OperationKind.AddFile)
else
{
return null;
return _project!.AdditionalTexts.Single(a => a.Path.EndsWith("Counter.razor", StringComparison.OrdinalIgnoreCase));
}
return null;
}

private const string IndependentRazorFile = "<h1>Independent File</h1>";
Expand Down