Skip to content

Commit

Permalink
Add feature: allows to iterate executing Actions with iterations pa…
Browse files Browse the repository at this point in the history
…rameter in `Start` extension methods;

Update nuget-dependencies
  • Loading branch information
unchase committed May 2, 2020
1 parent 8628171 commit 5a4688c
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 39 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

These are the changes to each version that has been released on the official [NuGet Gallery (Common)](https://www.nuget.org/packages/Unchase.FluentPerformanceMeter) and [NuGet Gallery (MVC)](https://www.nuget.org/packages/Unchase.FluentPerformanceMeter.AspNetCore.Mvc).

## v2.1.1 `(2020-05-02)`

- [x] Add feature: allows to iterate executing Actions with `iterations` parameter in `Start` extension methods
- [x] Update nuget-dependencies

## v2.1.0 `(2020-03-14)`

- [x] Add feature: allows to to get the performance measurements results using the built-in **DI**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Authors>Unchase</Authors>
<Company>Unchase</Company>
<Description>Unchase Fluent Performance Meter is an open-source and cross-platform .Net Standart 2.0 library is designed for the method’s performance measurement.</Description>
Expand All @@ -16,8 +16,8 @@
<RepositoryType>Github</RepositoryType>
<PackageTags>performance benchmark benchmarking csharp dot-net</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<AssemblyVersion>2.1.1.0</AssemblyVersion>
<FileVersion>2.1.1.0</FileVersion>
<DocumentationFile>Unchase.FluentPerformanceMeter.AspNetCore.Mvc.xml</DocumentationFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ public ActionResult PublicTestGetSimpleMethodWithActionThrowsException()
return Ok();
}

/// <summary>
/// Test GET method with simple performance watching (with executing some iterated code (Action)).
/// </summary>
[HttpGet("SimpleStartWatchingWithActionAndIterations")]
public ActionResult PublicTestGetSimpleMethodWithActionAndIterations(uint iterations = 1)
{
using var pm = PerformanceMeter<PerformanceMeterController>.StartWatching();

// execute an action that throws the exception to be handled by the exception handler
pm.Executing()
.Start(() => Debug.WriteLine($"Iterations: {iterations}"), iterations);

return Ok();
}

/// <summary>
/// Test GET method with simple performance watching (with executing some code (Action and Func{string}) without performance watching).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="5.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 26 additions & 10 deletions Unchase.FluentPerformanceMeter/Builders/CodeExecutorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,19 @@ internal async ValueTask<TResult> ExecuteAsync<TResult>(ValueTask<TResult> task,
/// Execute the Action.
/// </summary>
/// <param name="action">Executed Action.</param>
internal void Execute(Action action)
/// <param name="iterations">Number of executing Action iterations.</param>
internal void Execute(Action action, uint iterations = 1)
{
if (this._useExceptionHandler)
{
if (this._stopWatching)
this.PerformanceMeter.InnerStopwatch.Stop();
try
{
action();
for (var i = 0; i < iterations; i++)
{
action();
}
}
catch (TException ex)
{
Expand All @@ -196,7 +200,10 @@ internal void Execute(Action action)
{
if (this._stopWatching)
this.PerformanceMeter.InnerStopwatch.Stop();
action();
for (var i = 0; i < iterations; i++)
{
action();
}
this.PerformanceMeter.InnerStopwatch.Start();
}
}
Expand All @@ -205,15 +212,19 @@ internal void Execute(Action action)
/// Execute the Task.
/// </summary>
/// <param name="task">Executed Task.</param>
internal async ValueTask ExecuteAsync(ValueTask task)
/// <param name="iterations">Number of executing Task iterations.</param>
internal async ValueTask ExecuteAsync(ValueTask task, uint iterations = 1)
{
if (this._useExceptionHandler)
{
if (this._stopWatching)
this.PerformanceMeter.InnerStopwatch.Stop();
try
{
await task;
for (var i = 0; i < iterations; i++)
{
await task;
}
}
catch (TException ex)
{
Expand All @@ -235,7 +246,10 @@ internal async ValueTask ExecuteAsync(ValueTask task)
{
if (this._stopWatching)
this.PerformanceMeter.InnerStopwatch.Stop();
await task;
for (var i = 0; i < iterations; i++)
{
await task;
}
this.PerformanceMeter.InnerStopwatch.Start();
}
}
Expand Down Expand Up @@ -286,9 +300,10 @@ public static CodeExecutorBuilder<TClass, TException> WithExceptionHandler<TClas
/// <typeparam name="TException">Type of exception of the exception handler.</typeparam>
/// <param name="codeExecutorBuilder"><see cref="CodeExecutorBuilder{TClass, TException}"/>.</param>
/// <param name="action">Executed Action.</param>
public static void Start<TClass, TException>(this CodeExecutorBuilder<TClass, TException> codeExecutorBuilder, Action action) where TClass : class where TException : Exception
/// <param name="iterations">Number of executing Action iterations.</param>
public static void Start<TClass, TException>(this CodeExecutorBuilder<TClass, TException> codeExecutorBuilder, Action action, uint iterations = 1) where TClass : class where TException : Exception
{
codeExecutorBuilder.Execute(action);
codeExecutorBuilder.Execute(action, iterations);
}

/// <summary>
Expand All @@ -298,9 +313,10 @@ public static void Start<TClass, TException>(this CodeExecutorBuilder<TClass, TE
/// <typeparam name="TException">Type of exception of the exception handler.</typeparam>
/// <param name="codeExecutorBuilder"><see cref="CodeExecutorBuilder{TClass, TException}"/>.</param>
/// <param name="task">Executed Task.</param>
public static async ValueTask StartAsync<TClass, TException>(this CodeExecutorBuilder<TClass, TException> codeExecutorBuilder, ValueTask task) where TClass : class where TException : Exception
/// <param name="iterations">Number of executing Task iterations.</param>
public static async ValueTask StartAsync<TClass, TException>(this CodeExecutorBuilder<TClass, TException> codeExecutorBuilder, ValueTask task, uint iterations = 1) where TClass : class where TException : Exception
{
await codeExecutorBuilder.ExecuteAsync(task).ConfigureAwait(false);
await codeExecutorBuilder.ExecuteAsync(task, iterations).ConfigureAwait(false);
}

/// <summary>
Expand Down
22 changes: 13 additions & 9 deletions Unchase.FluentPerformanceMeter/PerformanceMeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,21 +1376,23 @@ public CodeExecutorBuilder<TClass, Exception> Executing()
/// Execute the Action.
/// </summary>
/// <param name="action">Executed Action.</param>
public void Inline(Action action)
/// <param name="iterations">Number of executing Action iterations.</param>
public void Inline(Action action, uint iterations = 1)
{
new CodeExecutorBuilder<TClass, Exception>(this).Start(action);
new CodeExecutorBuilder<TClass, Exception>(this).Start(action, iterations);
}

/// <summary>
/// Execute the Task.
/// </summary>
/// <param name="task">Executed Task.</param>
/// <param name="iterations">Number of executing Task iterations.</param>
/// <returns>
/// Returns <see cref="Task"/>.
/// </returns>
public async ValueTask InlineAsync(ValueTask task)
public async ValueTask InlineAsync(ValueTask task, uint iterations = 1)
{
await new CodeExecutorBuilder<TClass, Exception>(this).StartAsync(task);
await new CodeExecutorBuilder<TClass, Exception>(this).StartAsync(task, iterations);
}

/// <summary>
Expand All @@ -1414,7 +1416,7 @@ public TResult Inline<TResult>(Func<TResult> func, TResult defaultResult = defau
/// <param name="task">Executed Task.</param>
/// <param name="defaultResult">Default result if exception will occured.</param>
/// <returns>
/// Resturns Task of result.
/// Returns Task of result.
/// </returns>
public async ValueTask<TResult> InlineAsync<TResult>(ValueTask<TResult> task, TResult defaultResult = default)
{
Expand All @@ -1429,21 +1431,23 @@ public async ValueTask<TResult> InlineAsync<TResult>(ValueTask<TResult> task, TR
/// Execute the Action.
/// </summary>
/// <param name="action">Executed Action.</param>
public void InlineIgnored(Action action)
/// <param name="iterations">Number of executing Action iterations.</param>
public void InlineIgnored(Action action, uint iterations = 1)
{
new CodeExecutorBuilder<TClass, Exception>(this).WithoutWatching().Start(action);
new CodeExecutorBuilder<TClass, Exception>(this).WithoutWatching().Start(action, iterations);
}

/// <summary>
/// Execute the Task.
/// </summary>
/// <param name="task">Executed Task.</param>
/// <param name="iterations">Number of executing Task iterations.</param>
/// <returns>
/// Returns <see cref="Task"/>.
/// </returns>
public async ValueTask InlineIgnoredAsync(ValueTask task)
public async ValueTask InlineIgnoredAsync(ValueTask task, uint iterations = 1)
{
await new CodeExecutorBuilder<TClass, Exception>(this).WithoutWatching().StartAsync(task);
await new CodeExecutorBuilder<TClass, Exception>(this).WithoutWatching().StartAsync(task, iterations);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<PackageIcon>icon.png</PackageIcon>
<PackageIconUrl />
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Version>2.1.0</Version>
<AssemblyVersion>2.1.1.0</AssemblyVersion>
<FileVersion>2.1.1.0</FileVersion>
<Version>2.1.1</Version>
<DocumentationFile>Unchase.FluentPerformanceMeter.xml</DocumentationFile>
</PropertyGroup>

Expand All @@ -37,7 +37,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.3" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>

</Project>
26 changes: 17 additions & 9 deletions Unchase.FluentPerformanceMeter/Unchase.FluentPerformanceMeter.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a4688c

Please sign in to comment.