Add benchmarks project

This commit is contained in:
Matthew Parker [SSW]
2025-01-11 13:26:04 +10:00
parent ced3a70988
commit 52671f0252
7 changed files with 67 additions and 17 deletions

View File

@@ -18,6 +18,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.Photino", "src\Sha
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpIDE.Application", "src\SharpIDE.Application\SharpIDE.Application.csproj", "{D7D5D39E-DA3A-4B10-8F40-B07B769347F4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B6835010-35FA-4C74-AB48-009FB923185D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Roslyn.Benchmarks", "tests\Roslyn.Benchmarks\Roslyn.Benchmarks.csproj", "{252CE098-2F9A-4DA3-A172-EE1167B335BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -35,9 +39,14 @@ Global
{D7D5D39E-DA3A-4B10-8F40-B07B769347F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7D5D39E-DA3A-4B10-8F40-B07B769347F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7D5D39E-DA3A-4B10-8F40-B07B769347F4}.Release|Any CPU.Build.0 = Release|Any CPU
{252CE098-2F9A-4DA3-A172-EE1167B335BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{252CE098-2F9A-4DA3-A172-EE1167B335BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{252CE098-2F9A-4DA3-A172-EE1167B335BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{252CE098-2F9A-4DA3-A172-EE1167B335BF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E35167E1-0FF4-4194-97A8-CC95EDA224CD} = {F4ED837F-888A-4D01-BCED-C360B9CE0865}
{D7D5D39E-DA3A-4B10-8F40-B07B769347F4} = {F4ED837F-888A-4D01-BCED-C360B9CE0865}
{252CE098-2F9A-4DA3-A172-EE1167B335BF} = {B6835010-35FA-4C74-AB48-009FB923185D}
EndGlobalSection
EndGlobal

View File

@@ -18,23 +18,23 @@ public static class RoslynTest
Console.WriteLine($"Solution loaded in {timer.ElapsedMilliseconds}ms");
Console.WriteLine();
foreach (var project in solution.Projects)
{
Console.WriteLine($"Project: {project.Name}");
foreach (var document in project.Documents)
{
Console.WriteLine($"Document: {document.Name}");
var syntaxTree = await document.GetSyntaxTreeAsync();
var root = await syntaxTree!.GetRootAsync();
var classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, root.FullSpan);
foreach (var span in classifiedSpans)
{
var classifiedSpan = root.GetText().GetSubText(span.TextSpan);
Console.WriteLine($"{span.TextSpan}: {span.ClassificationType}");
Console.WriteLine(classifiedSpan);
}
}
}
// foreach (var project in solution.Projects)
// {
// Console.WriteLine($"Project: {project.Name}");
// foreach (var document in project.Documents)
// {
// Console.WriteLine($"Document: {document.Name}");
// var syntaxTree = await document.GetSyntaxTreeAsync();
// var root = await syntaxTree!.GetRootAsync();
// var classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, root.FullSpan);
// foreach (var span in classifiedSpans)
// {
// var classifiedSpan = root.GetText().GetSubText(span.TextSpan);
// Console.WriteLine($"{span.TextSpan}: {span.ClassificationType}");
// Console.WriteLine(classifiedSpan);
// }
// }
// }
}
}

View File

@@ -58,6 +58,7 @@
private void LoadSolution(string solutionPath)
{
return;
var solutionFile = GetNodesInSolution.ParseSolutionFileFromPath("C:/Users/Matthew/Documents/Git/amazon/ClientPortal.sln");
ArgumentNullException.ThrowIfNull(solutionFile);
_solutionFile = solutionFile;

View File

@@ -7,6 +7,7 @@
{
protected override async Task OnInitializedAsync()
{
await Task.Delay(100);
await RoslynTest.Analyse("C:/Users/Matthew/Documents/Git/StatusApp/StatusApp.sln");
}
}

View File

@@ -0,0 +1,19 @@
using System.Diagnostics;
using BenchmarkDotNet.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
namespace Roslyn.Benchmarks;
public class MSBuildWorkspaceBenchmarks
{
private const string _solutionFilePath = "C:/Users/Matthew/Documents/Git/StatusApp/StatusApp.sln";
[Benchmark]
public async Task<Solution> ParseSolutionFileFromPath()
{
var workspace = MSBuildWorkspace.Create();
var solution = await workspace.OpenSolutionAsync(_solutionFilePath);
return solution;
}
}

View File

@@ -0,0 +1,4 @@
using BenchmarkDotNet.Running;
using Roslyn.Benchmarks;
BenchmarkRunner.Run<MSBuildWorkspaceBenchmarks>();

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.12.0" />
</ItemGroup>
</Project>