Skip to content

Commit

Permalink
feat: update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
EngRajabi committed Feb 23, 2024
1 parent 7acbfe1 commit 211588e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Binary file modified Supernova.Enum.Generators.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 30 additions & 3 deletions test/Console.Test.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ namespace Console.Test.Benchmark;
[EnumGenerator]
public enum UserType
{
[Display(Name = "مرد")] Men,
[Display(Name = "مرد", Description = "men")] Men,

[Display(Name = "زن")] Women,
[Display(Name = "زن", Description = "women")] Women,

//[Display(Name = "نامشخص")]
None
Expand All @@ -45,7 +45,7 @@ static void Main(string[] args)
.AddColumn(StatisticColumn.OperationsPerSecond)
.AddColumn(BaselineRatioColumn.RatioMean)
.AddColumn(RankColumn.Arabic)
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60)
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80)
.WithIterationCount(32)
.WithInvocationCount(64)
.WithIterationTime(TimeInterval.FromSeconds(120))
Expand Down Expand Up @@ -97,6 +97,18 @@ public string FastToDisplay()
return UserType.Men.ToDisplayFast();
}

[Benchmark]
public string NativeToDescription()
{
return UserType.Men.ToDescriptionNative();
}

[Benchmark]
public string FastToDescription()
{
return UserType.Men.ToDescriptionFast();
}

[Benchmark]
public UserType[] NativeGetValues()
{
Expand Down Expand Up @@ -149,6 +161,21 @@ public static string ToDisplayNative(this Enum value)

var propValue = attribute.GetType().GetProperty("Name")?.GetValue(attribute, null);

return propValue?.ToString();
}
public static string ToDescriptionNative(this Enum value)
{
if (value is null)
throw new ArgumentNullException(nameof(value));

var attribute = value.GetType().GetField(value.ToString())?
.GetCustomAttributes<DisplayAttribute>(false).FirstOrDefault();

if (attribute == null)
return value.ToString();

var propValue = attribute.GetType().GetProperty("Description")?.GetValue(attribute, null);

return propValue?.ToString();
}
}

0 comments on commit 211588e

Please sign in to comment.