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

update benchmark #3229

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion benchmark/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -13,10 +13,12 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetVersion)" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="$(BenchmarkDotNetDiagnosticsWindowsVersion)" />
<!--<PackageReference Include="Microsoft.Graph" Version="5.51.0" />-->
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Microsoft.Identity.Web.DownstreamApi\Microsoft.Identity.Web.DownstreamApi.csproj" />
<ProjectReference Include="..\src\Microsoft.Identity.Web.GraphServiceClient\Microsoft.Identity.Web.GraphServiceClient.csproj" />
<ProjectReference Include="..\src\Microsoft.Identity.Web\Microsoft.Identity.Web.csproj" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions benchmark/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<PropertyGroup>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>net8.0</TargetFrameworks>
<SignAssembly>True</SignAssembly>
<IsPackable>false</IsPackable>
<EnablePackageValidation>false</EnablePackageValidation>
<AssemblyOriginatorKeyFile>../build/MSAL.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>
<DelaySign>True</DelaySign>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)..\build\msal.snk</AssemblyOriginatorKeyFile>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
57 changes: 57 additions & 0 deletions benchmark/GraphServiceClientBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using BenchmarkDotNet.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Web;
using Microsoft.Graph;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;

#pragma warning disable CA1050 // Declare types in namespaces
jennyf19 marked this conversation as resolved.
Show resolved Hide resolved
public class GraphServiceClientBenchmark
#pragma warning restore CA1050 // Declare types in namespaces
{
private readonly GraphServiceClient _graphServiceClient;

public GraphServiceClientBenchmark()
{
var services = new ServiceCollection();
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();

int count = 0; // Initialize count

// Add necessary services and configurations
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(options =>
{
// Verification of the fix for #2456
if (count > 0)
{
throw new ArgumentException("AddMicrosoftIdentityWebApp(delegate). the delegate" +
"is called more than once");
}
else
{
count++;
}

configuration.Bind("AzureAd", options);
})
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph(configuration.GetSection("GraphBeta"))
.AddDownstreamApi("GraphBeta", configuration.GetSection("GraphBeta"))
.AddInMemoryTokenCaches();

var serviceProvider = services.BuildServiceProvider();
_graphServiceClient = serviceProvider.GetRequiredService<GraphServiceClient>();
}

[Benchmark]
public void GetUser()
{
_graphServiceClient.Me.ToGetRequestInformation();
}
}
1 change: 1 addition & 0 deletions benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static void Main(string[] args)
var benchmarkConfig = ManualConfig.Union(DefaultConfig.Instance, new BenchmarkConfig());
#endif
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, benchmarkConfig);
BenchmarkRunner.Run<GraphServiceClientBenchmark>();
jennyf19 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Loading