Skip to content

Commit 0f550f5

Browse files
author
Mohamed Shaban
authored
add perf project (Azure#21519)
1 parent d79ed17 commit 0f550f5

File tree

8 files changed

+169
-1
lines changed

8 files changed

+169
-1
lines changed

sdk/textanalytics/Azure.AI.TextAnalytics/Azure.AI.TextAnalytics.sln

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.AI.TextAnalytics", "s
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.AI.TextAnalytics.Tests", "tests\Azure.AI.TextAnalytics.Tests.csproj", "{5FB75291-CE2C-44FC-86AD-5FBB954457B8}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{FD1CFA70-4C03-42AF-9D95-E3E974F9AC9A}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{FD1CFA70-4C03-42AF-9D95-E3E974F9AC9A}"
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core", "..\..\core\Azure.Core\src\Azure.Core.csproj", "{EB0781C6-6C18-4C2A-8BDB-D61A1460AB09}"
1313
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{44C5D4FF-7404-4D7A-977B-8E1EAADA7D1D}"
15+
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.AI.TextAnalytics.Perf", "perf\Azure.AI.TextAnalytics.Perf\Azure.AI.TextAnalytics.Perf.csproj", "{2EE6085E-A0D6-4D25-B6E1-E5BA579E7D7C}"
17+
EndProject
1418
Global
1519
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1620
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +37,14 @@ Global
3337
{EB0781C6-6C18-4C2A-8BDB-D61A1460AB09}.Debug|Any CPU.Build.0 = Debug|Any CPU
3438
{EB0781C6-6C18-4C2A-8BDB-D61A1460AB09}.Release|Any CPU.ActiveCfg = Release|Any CPU
3539
{EB0781C6-6C18-4C2A-8BDB-D61A1460AB09}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{44C5D4FF-7404-4D7A-977B-8E1EAADA7D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{44C5D4FF-7404-4D7A-977B-8E1EAADA7D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{44C5D4FF-7404-4D7A-977B-8E1EAADA7D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{44C5D4FF-7404-4D7A-977B-8E1EAADA7D1D}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{2EE6085E-A0D6-4D25-B6E1-E5BA579E7D7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{2EE6085E-A0D6-4D25-B6E1-E5BA579E7D7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{2EE6085E-A0D6-4D25-B6E1-E5BA579E7D7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{2EE6085E-A0D6-4D25-B6E1-E5BA579E7D7C}.Release|Any CPU.Build.0 = Release|Any CPU
3648
EndGlobalSection
3749
GlobalSection(SolutionProperties) = preSolution
3850
HideSolutionNode = FALSE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj" />
9+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj" />
10+
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\src\Azure.AI.TextAnalytics.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core.TestFramework;
5+
6+
namespace Azure.AI.TextAnalytics.Perf
7+
{
8+
/// <summary>
9+
/// Represents the ambient environment in which the test suite is being run, offering access to information such
10+
/// as environment variables.
11+
/// </summary>
12+
public sealed class PerfTestEnvironment : TestEnvironment
13+
{
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="PerfTestEnvironment"/> class.
16+
/// </summary>
17+
private PerfTestEnvironment()
18+
{
19+
}
20+
21+
/// <summary>
22+
/// The shared instance of the <see cref="PerfTestEnvironment"/> to be used during test runs.
23+
/// </summary>
24+
public static PerfTestEnvironment Instance { get; } = new PerfTestEnvironment();
25+
26+
/// <summary>
27+
/// The endpoint of the Text Analytics account to test against.
28+
/// </summary>
29+
/// <value>The endpoint, read from the "TEXT_ANALYTICS_ENDPOINT" environment variable.</value>
30+
public string Endpoint => GetVariable("TEXT_ANALYTICS_ENDPOINT");
31+
32+
/// <summary>
33+
/// The API key of the Text Analytics account to test against.
34+
/// </summary>
35+
/// <value>The API key, read from the "TEXT_ANALYTICS_API_KEY" environment variable.</value>
36+
public string ApiKey => GetVariable("TEXT_ANALYTICS_API_KEY");
37+
}
38+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using Azure.Test.Perf;
6+
7+
namespace Azure.AI.TextAnalytics.Perf
8+
{
9+
public abstract class TextAnalyticsTest<TOptions> : PerfTest<TOptions> where TOptions : PerfOptions
10+
{
11+
public TextAnalyticsTest(TOptions options) : base(options)
12+
{
13+
TestEnvironment = PerfTestEnvironment.Instance;
14+
}
15+
16+
protected PerfTestEnvironment TestEnvironment { get; }
17+
}
18+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Reflection;
5+
using Azure.Test.Perf;
6+
7+
await PerfProgram.Main(Assembly.GetEntryAssembly(), args);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Test.Perf;
5+
using CommandLine;
6+
7+
namespace Azure.AI.TextAnalytics.Perf
8+
{
9+
public class TextAnalyticsCountOptions : PerfOptions
10+
{
11+
[Option('c', "count", Default = 1000, HelpText = "Number of items")]
12+
public int Count { get; set; }
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Azure Text Analytics performance tests
2+
3+
The assets in this area comprise a set of performance tests for the [Azure Text Analytics client library for .NET](https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/textanalytics/Azure.AI.TextAnalytics) and its associated ecosystem. The artifacts in this library are intended to be used primarily with the Azure SDK engineering system's testing infrastructure, but may also be run as stand-alone applications from the command line.
4+
5+
## Running performance tests
6+
7+
Run the Text Analytics client library performance tests by executing the command-line application using the `dotnet run` command or, in some environments, your operating system's executable support. The performance tests rely on the same set of environment variables used by the Text Analytics client library's test suite.
8+
An example test run would be like this:
9+
```console
10+
dotnet run --framework netcoreapp2.1 DetectLanguagePerf
11+
```
12+
13+
## Contributing
14+
15+
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
16+
17+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
18+
19+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
20+
21+
Please see our [contributing guide](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/eventhub/Azure.Messaging.EventHubs/CONTRIBUTING.md) for more information.
22+
23+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftextanalytics%2FAzure.AI.TextAnalytics%2Fperf%2FAzure.AI.TextAnalytics.Perf%2FREADME.png)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace Azure.AI.TextAnalytics.Perf
10+
{
11+
public sealed class DetectLanguagePerf
12+
13+
: TextAnalyticsTest<TextAnalyticsCountOptions>
14+
{
15+
private readonly TextAnalyticsClient _client;
16+
17+
private List<string> _batchDocuments;
18+
19+
public DetectLanguagePerf(TextAnalyticsCountOptions options) : base(options)
20+
{
21+
// create client
22+
_client = new TextAnalyticsClient(new Uri(TestEnvironment.Endpoint), new AzureKeyCredential(TestEnvironment.ApiKey));
23+
24+
// create input docs
25+
var documentCount = options.Count;
26+
_batchDocuments = new List<string> { };
27+
for (int i = 1; i <= documentCount; i++)
28+
{
29+
_batchDocuments.Add("Detta är ett dokument skrivet på engelska.");
30+
}
31+
}
32+
33+
public override async Task RunAsync(CancellationToken cancellationToken)
34+
{
35+
await _client.DetectLanguageBatchAsync(_batchDocuments, cancellationToken: cancellationToken);
36+
}
37+
38+
public override void Run(CancellationToken cancellationToken)
39+
{
40+
_client.DetectLanguageBatch(_batchDocuments, cancellationToken: cancellationToken);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)