Skip to content

Commit 7485b19

Browse files
committed
Made some benchmarking
1 parent eb0198e commit 7485b19

12 files changed

+107
-13
lines changed

samples/Thinktecture.Runtime.Extensions.Benchmarking/BenchmarkContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public BenchmarkContext()
1616
var services = new ServiceCollection()
1717
.AddLogging(builder => builder.AddConsole())
1818
.AddDbContext<BenchmarkDbContext>(builder => builder
19-
.UseSqlServer("Server=localhost;Database=TT_RE_Benchmarking;Integrated Security=true;")
19+
.UseSqlServer("Server=localhost;Database=TT_RE_Benchmarking;Integrated Security=true;TrustServerCertificate=true;")
2020
.UseLoggerFactory(NullLoggerFactory.Instance)
2121
.UseValueObjectValueConverter());
2222

samples/Thinktecture.Runtime.Extensions.Benchmarking/Benchmarks/ItemSearch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Thinktecture.Benchmarks;
99

10-
[MemoryDiagnoser]
1110
public class ItemSearch
1211
{
1312
public class SmartEnum

samples/Thinktecture.Runtime.Extensions.Benchmarking/Benchmarks/LoadingSmartEnums.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace Thinktecture.Benchmarks;
1010

1111
// ReSharper disable InconsistentNaming
12-
[MemoryDiagnoser]
1312
public class LoadingSmartEnums
1413
{
1514
private BenchmarkContext? _benchmarkContext;

samples/Thinktecture.Runtime.Extensions.Benchmarking/Benchmarks/LoadingValueObjects.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Thinktecture.Benchmarks;
99

1010
// ReSharper disable InconsistentNaming
11-
[MemoryDiagnoser]
1211
public class LoadingValueObjects
1312
{
1413
private BenchmarkContext? _benchmarkContext;
@@ -19,6 +18,7 @@ public class LoadingValueObjects
1918

2019
private readonly Entity_with_ValueObjects[] _Entity_with_ValueObjects = Enumerable.Range(1, _NUMBER_OF_ENTITIES).Select(i => new Entity_with_ValueObjects(i)).ToArray();
2120
private readonly Entity_without_ValueObjects[] _Entity_without_ValueObjects = Enumerable.Range(1, _NUMBER_OF_ENTITIES).Select(i => new Entity_without_ValueObjects(i)).ToArray();
21+
private readonly Entity_with_StructValueObjects[] _Entity_with_StructValueObjects = Enumerable.Range(1, _NUMBER_OF_ENTITIES).Select(i => new Entity_with_StructValueObjects(i)).ToArray();
2222

2323
[GlobalSetup]
2424
public void Initialize()
@@ -36,6 +36,9 @@ public void Initialize()
3636
_dbContext.RemoveRange(_dbContext.Entity_without_ValueObjects);
3737
_dbContext.Entity_without_ValueObjects.AddRange(_Entity_without_ValueObjects);
3838

39+
_dbContext.RemoveRange(_dbContext.Entity_with_StructValueObjects);
40+
_dbContext.Entity_with_StructValueObjects.AddRange(_Entity_with_StructValueObjects);
41+
3942
_dbContext.SaveChanges();
4043
}
4144

@@ -63,4 +66,10 @@ public async Task Entity_without_ValueObjects()
6366
{
6467
await _dbContext!.Entity_without_ValueObjects.ToListAsync();
6568
}
69+
70+
[Benchmark]
71+
public async Task Entity_with_StructValueObjects()
72+
{
73+
await _dbContext!.Entity_with_StructValueObjects.ToListAsync();
74+
}
6675
}

samples/Thinktecture.Runtime.Extensions.Benchmarking/Benchmarks/SingleItemCollectionBenchmarks.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Thinktecture.Benchmarks;
55

6-
[MemoryDiagnoser]
76
public class SingleItemCollectionBenchmarks
87
{
98
private readonly IReadOnlyList<int> _singleItemCollection = SingleItem.Collection(42);

samples/Thinktecture.Runtime.Extensions.Benchmarking/Benchmarks/SingleItemSetBenchmarks.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Thinktecture.Benchmarks;
55

6-
[MemoryDiagnoser]
76
public class SingleItemSetBenchmarks
87
{
98
private readonly IReadOnlySet<int> _singleItemSet = SingleItem.Set(42);

samples/Thinktecture.Runtime.Extensions.Benchmarking/Database/BenchmarkDbContext.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class BenchmarkDbContext : DbContext
1414

1515
public DbSet<Entity_with_ValueObjects> Entity_with_ValueObjects { get; set; } = null!;
1616
public DbSet<Entity_without_ValueObjects> Entity_without_ValueObjects { get; set; } = null!;
17+
public DbSet<Entity_with_StructValueObjects> Entity_with_StructValueObjects { get; set; } = null!;
1718

1819
public BenchmarkDbContext(DbContextOptions<BenchmarkDbContext> options)
1920
: base(options)
@@ -66,5 +67,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6667
builder.Property(e => e.Name).HasMaxLength(100);
6768
builder.Property(e => e.Description).HasMaxLength(200);
6869
});
70+
71+
modelBuilder.Entity<Entity_with_StructValueObjects>(builder =>
72+
{
73+
builder.Property(e => e.Id).ValueGeneratedNever();
74+
builder.Property(e => e.Name).HasMaxLength(100);
75+
builder.Property(e => e.Description).HasMaxLength(200);
76+
});
6977
}
7078
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace Thinktecture.Database;
5+
6+
[ValueObject]
7+
public readonly partial struct DescriptionStruct
8+
{
9+
private readonly string _value;
10+
11+
static partial void ValidateFactoryArguments(ref ValidationResult? validationResult, ref string value)
12+
{
13+
if (String.IsNullOrWhiteSpace(value))
14+
{
15+
validationResult = new ValidationResult("Description cannot be empty.");
16+
return;
17+
}
18+
19+
value = value.Trim();
20+
21+
if (value.Length < 2)
22+
validationResult = new ValidationResult("Description cannot be less than 2 characters.");
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Thinktecture.Database;
2+
3+
// ReSharper disable InconsistentNaming
4+
public class Entity_with_StructValueObjects
5+
{
6+
public int Id { get; set; }
7+
public NameStruct Name { get; set; }
8+
public DescriptionStruct Description { get; set; }
9+
10+
// ReSharper disable once UnusedMember.Local
11+
private Entity_with_StructValueObjects(int id, NameStruct name, DescriptionStruct description)
12+
{
13+
Id = id;
14+
Name = name;
15+
Description = description;
16+
}
17+
18+
public Entity_with_StructValueObjects(int index)
19+
{
20+
Id = index;
21+
Name = NameStruct.Create($"Name {index}");
22+
Description = DescriptionStruct.Create($"Description {index}");
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace Thinktecture.Database;
5+
6+
[ValueObject]
7+
public readonly partial struct NameStruct
8+
{
9+
private readonly string _value;
10+
11+
static partial void ValidateFactoryArguments(ref ValidationResult? validationResult, ref string value)
12+
{
13+
if (String.IsNullOrWhiteSpace(value))
14+
{
15+
validationResult = new ValidationResult("Name cannot be empty.");
16+
return;
17+
}
18+
19+
value = value.Trim();
20+
21+
if (value.Length < 2)
22+
validationResult = new ValidationResult("Name cannot be less than 2 characters.");
23+
}
24+
}

0 commit comments

Comments
 (0)