-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Optimisation] More efficient code generation for unmanaged types and arrays
- Loading branch information
1 parent
ab568e0
commit a1ab9fc
Showing
44 changed files
with
748 additions
and
3,394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using MemoryPack; | ||
using MessagePack; | ||
using Nino.Core; | ||
|
||
namespace Nino.Benchmark; | ||
|
||
[NinoType] | ||
[MemoryPackable] | ||
[MessagePackObject] | ||
public partial class SimpleClass | ||
{ | ||
[Key(0)] | ||
public int Id; | ||
|
||
[Key(1)] | ||
public string Name { get; set; } | ||
Check warning on line 19 in src/Nino.Benchmark/Data.cs GitHub Actions / build
|
||
[Key(2)] | ||
public int[] Numbers { get; set; } | ||
[Key(3)] | ||
public List<DateTime> Dates { get; set; } | ||
|
||
[Key(4)] | ||
public Dictionary<int, string> Map1; | ||
|
||
[Key(5)] | ||
public Dictionary<int, int> Map2 { get; set; } | ||
|
||
public static SimpleClass Create() | ||
{ | ||
Random random = new Random(); | ||
return new SimpleClass | ||
{ | ||
Id = random.Next(), | ||
Name = "SimpleClass", | ||
Numbers = Enumerable.Range(0, 100).Select(n => random.Next()).ToArray(), | ||
Dates = Enumerable.Range(0, 10).Select(n => DateTime.Now.AddSeconds(random.Next())).ToList(), | ||
Map1 = Enumerable.Range(0, 10).ToDictionary(n => n, n => n.ToString()), | ||
Map2 = Enumerable.Range(0, 10).ToDictionary(n => n, n => n * 2) | ||
}; | ||
} | ||
} | ||
|
||
[NinoType] | ||
[MemoryPackable] | ||
[MessagePackObject] | ||
public partial struct SimpleStruct | ||
{ | ||
[Key(0)] | ||
public int Id; | ||
[Key(1)] | ||
public DateTime CreateTime; | ||
|
||
public static SimpleStruct Create() | ||
{ | ||
Random random = new Random(); | ||
return new SimpleStruct | ||
{ | ||
Id = random.Next(), | ||
CreateTime = DateTime.Now.AddSeconds(random.Next()) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using BenchmarkDotNet.Columns; | ||
using BenchmarkDotNet.Reports; | ||
using BenchmarkDotNet.Running; | ||
|
||
|
||
namespace Nino.Benchmark; | ||
public class PayloadColumnAttribute : ColumnConfigBaseAttribute | ||
{ | ||
public PayloadColumnAttribute() | ||
: base(new PayloadColumn()) | ||
{ | ||
} | ||
} | ||
|
||
public class PayloadColumn : IColumn | ||
{ | ||
public string Id => nameof(PayloadColumn); | ||
|
||
public string ColumnName => "Payload"; | ||
|
||
public bool AlwaysShow => true; | ||
|
||
public ColumnCategory Category => ColumnCategory.Custom; | ||
|
||
public int PriorityInCategory => 0; | ||
|
||
public bool IsNumeric => true; | ||
|
||
public UnitType UnitType => UnitType.Size; | ||
|
||
public string Legend => "Payload size"; | ||
|
||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase) | ||
{ | ||
var methodInfo = benchmarkCase.Descriptor.WorkloadMethod; | ||
|
||
if (methodInfo.ReturnType == typeof(byte[])) | ||
{ | ||
var instance = Activator.CreateInstance(benchmarkCase.Descriptor.Type); | ||
var result = (byte[])methodInfo.Invoke(instance, null)!; | ||
return new SizeValue(result.LongLength).ToString(null); | ||
} | ||
else | ||
{ | ||
return "-"; | ||
} | ||
} | ||
|
||
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style) | ||
{ | ||
return GetValue(summary, benchmarkCase); | ||
} | ||
|
||
public bool IsAvailable(Summary summary) | ||
{ | ||
return true; | ||
} | ||
|
||
public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.