Skip to content

Commit

Permalink
Refactor benchmarks and improve currency initialization.
Browse files Browse the repository at this point in the history
Renamed benchmark methods for clarity and added a new benchmark for `CurrencyInfo`. Updated documentation with refined performance metrics and adjusted code comments for accuracy. Removed outdated references in `CONTRIBUTING.md`.
  • Loading branch information
RemyDuijkeren committed Jan 11, 2025
1 parent 5aab3b8 commit a48ef48
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 32 deletions.
74 changes: 56 additions & 18 deletions .idea/.idea.NodaMoney/.idea/workspace.xml

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

2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ can be accepted quickly.
* Make sure you have a [GitHub account](https://github.com/signup/free)
* Fork the repository on GitHub (we use the [fork & pull model](https://help.github.com/articles/using-pull-requests))
* We use as branching strategy the [GitHub Flow Workflow](https://guides.github.com/introduction/flow/).
* Optionally you could install [ZenHub](https://www.zenhub.io/), a Chrome extension. This will add a task dashboard, file uploads
and +1 (likes) to GitHub.

## Making Changes
* If possible, create an issue for big improvements or features, so that people can discuss.
Expand Down
2 changes: 2 additions & 0 deletions NodaMoney.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=noda/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
6 changes: 3 additions & 3 deletions src/NodaMoney/CurrencyInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static CurrencyInfo Unregister(string code)

/// <summary>Builds the current <see cref="CurrencyInfoBuilder"/> object as a custom currency.</summary>
/// <returns>A <see cref="CurrencyInfo"/> instance that is build.</returns>
//// <exception cref="InvalidOperationException">The current CurrencyBuilder object has a property that must be set before the currency can be registered.</exception>
/// <exception cref="InvalidOperationException">The current CurrencyBuilder object has a property that must be set before the currency can be registered.</exception>
public CurrencyInfo Build()
{
// throw new InvalidOperationException("The current CurrencyBuilder object has a property that must be set before the currency can be registered.");
Expand Down Expand Up @@ -158,8 +158,8 @@ public void Save(string fileName)
}

/// <summary>Sets the properties of the current <see cref="CurrencyInfoBuilder"/> object with the corresponding properties of
/// the specified <see cref="Currency"/> object, except for the code and namespace.</summary>
/// <param name="currency">The object whose properties will be used.</param>
/// the specified <see cref="CurrencyInfo"/> object, except for the code and namespace.</summary>
/// <param name="currencyInfo">The object whose properties will be used.</param>
public void LoadDataFromCurrencyInfo(CurrencyInfo currencyInfo)
{
if (currencyInfo == null)
Expand Down
9 changes: 8 additions & 1 deletion tests/Benchmark/InitializingCurrencyBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ namespace Benchmark;
public class InitializingCurrencyBenchmarks
{
[Benchmark]
public Currency FromCode()
public Currency CurrencyFromCode()
{
Currency currency = Currency.FromCode("EUR");
return currency;
}

[Benchmark]
public CurrencyInfo CurrencyInfoFromCode()
{
CurrencyInfo currency = CurrencyInfo.FromCode("EUR");
return currency;
}

// [Benchmark]
// public Currency FromCodeBeRef()
// {
Expand Down
2 changes: 1 addition & 1 deletion tests/Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BenchmarkDotNet.Running;
using Benchmark;

// var initializingCurrencyReport = BenchmarkRunner.Run<InitializingCurrencyBenchmarks>();
var initializingCurrencyReport = BenchmarkRunner.Run<InitializingCurrencyBenchmarks>();
// var initializingMoneyReport = BenchmarkRunner.Run<InitializingMoneyBenchmarks>();
// var moneyOperationsReport = BenchmarkRunner.Run<MoneyOperationsBenchmarks>();
// var moneyFormattingReport = BenchmarkRunner.Run<MoneyFormattingBenchmarks>();
Expand Down
11 changes: 4 additions & 7 deletions tests/NodaMoney.Tests/PerformanceReport.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ AMD Ryzen 7 5800H with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
|----------|---------:|--------:|---------:|-------:|----------:|
| FromCode | 443.7 ns | 8.90 ns | 14.87 ns | 0.0753 | 632 B |
#### after
| Method | Mean | Error | StdDev | Allocated |
|--------- |---------:|---------:|---------:|----------:|
| FromCode | 15.34 ns | 0.060 ns | 0.056 ns | - |

| Method | Mean | Error | StdDev | Gen0 | Allocated |
|--------- |---------:|--------:|--------:|-------:|----------:|
| FromCode | 221.1 ns | 1.47 ns | 1.37 ns | 0.0143 | 120 B |
| Method | Mean | Error | StdDev | Allocated |
|----------------------|----------:|----------:|----------:|----------:|
| CurrencyFromCode | 13.950 ns | 0.0340 ns | 0.0284 ns | - |
| CurrencyInfoFromCode | 7.906 ns | 0.0563 ns | 0.0499 ns | - |

### after as class
| Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
Expand Down

0 comments on commit a48ef48

Please sign in to comment.