-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
192 additions
and
11 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
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
14 changes: 14 additions & 0 deletions
14
src/EFCore.Cassandra.Benchmarks/EFCore.Cassandra.Benchmarks.csproj
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\EFCore.Cassandra\EFCore.Cassandra.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,43 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
using EFCore.Cassandra.Benchmarks.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Cassandra.Storage; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace EFCore.Cassandra.Benchmarks | ||
{ | ||
public class FakeDbContext : DbContext | ||
{ | ||
public DbSet<Applicant> Applicants { get; set; } | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
optionsBuilder.UseCassandra("Contact Points=127.0.0.1;", opt => | ||
{ | ||
opt.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "cv"); | ||
}); | ||
} | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
var timeUuidConverter = new TimeUuidToGuidConverter(); | ||
modelBuilder.ForCassandraAddKeyspace("cv", new KeyspaceReplicationSimpleStrategyClass(2)); | ||
modelBuilder.Entity<Applicant>() | ||
.ToTable("applicants", "cv") | ||
.HasKey(p => new { p.Id, p.Order }); | ||
modelBuilder.Entity<Applicant>() | ||
.ForCassandraSetClusterColumns(_ => _.Order) | ||
.ForCassandraSetClusteringOrderBy(new[] { new CassandraClusteringOrderByOption("Order", CassandraClusteringOrderByOptions.ASC) }); | ||
modelBuilder.Entity<Applicant>() | ||
.Property(p => p.TimeUuid) | ||
.HasConversion(new TimeUuidToGuidConverter()); | ||
modelBuilder.Entity<Applicant>() | ||
.Property(p => p.Id) | ||
.HasColumnName("id"); | ||
modelBuilder.Entity<ApplicantAddress>() | ||
.ToUserDefinedType("applicant_addr", "cv") | ||
.HasNoKey(); | ||
} | ||
} | ||
} |
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,57 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
using BenchmarkDotNet.Attributes; | ||
using EFCore.Cassandra.Benchmarks.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EFCore.Cassandra.Benchmarks | ||
{ | ||
public class InsertData : IDisposable | ||
{ | ||
private readonly FakeDbContext _dbContext; | ||
private readonly Applicant[] _applicants; | ||
|
||
public InsertData() | ||
{ | ||
_dbContext = new FakeDbContext(); | ||
_applicants = Enumerable.Range(1, 5).Select(_ => BuildApplicant()).ToArray(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_dbContext.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void Add100Applicants() | ||
{ | ||
foreach (var applicant in _applicants) | ||
{ | ||
_dbContext.Applicants.Add(applicant); | ||
} | ||
|
||
_dbContext.SaveChanges(); | ||
} | ||
|
||
[Benchmark] | ||
public void AddRange100Applicants() | ||
{ | ||
_dbContext.Applicants.AddRange(_applicants); | ||
_dbContext.SaveChanges(); | ||
} | ||
|
||
private static Applicant BuildApplicant() | ||
{ | ||
return new Applicant | ||
{ | ||
Id = Guid.NewGuid(), | ||
Order = 0, | ||
Dic = new Dictionary<string, string>(), | ||
Lst = new List<string>(), | ||
LstInt = new List<int>() | ||
}; | ||
} | ||
} | ||
} |
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,37 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
using Cassandra; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Numerics; | ||
|
||
namespace EFCore.Cassandra.Benchmarks.Models | ||
{ | ||
public class Applicant | ||
{ | ||
public Guid Id { get; set; } | ||
public int Order { get; set; } | ||
public Guid ApplicantId { get; set; } | ||
public string LastName { get; set; } | ||
public long Long { get; set; } | ||
public bool Bool { get; set; } | ||
public decimal Decimal { get; set; } | ||
public double Double { get; set; } | ||
public float Float { get; set; } | ||
public int Integer { get; set; } | ||
public short SmallInt { get; set; } | ||
public DateTimeOffset DateTimeOffset { get; set; } | ||
public TimeUuid TimeUuid { get; set; } | ||
public sbyte Sbyte { get; set; } | ||
public BigInteger BigInteger { get; set; } | ||
public byte[] Blob { get; set; } | ||
public LocalDate LocalDate { get; set; } | ||
public IPAddress Ip { get; set; } | ||
public LocalTime LocalTime { get; set; } | ||
public IList<string> Lst { get; set; } | ||
public IList<int> LstInt { get; set; } | ||
public IDictionary<string, string> Dic { get; set; } | ||
public ApplicantAddress Address { get; set; } | ||
} | ||
} |
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,9 @@ | ||
| ||
namespace EFCore.Cassandra.Benchmarks.Models | ||
{ | ||
public class ApplicantAddress | ||
{ | ||
public int StreetNumber { get; set; } | ||
public string City { get; set; } | ||
} | ||
} |
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,15 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
using BenchmarkDotNet.Running; | ||
using System.Threading.Tasks; | ||
|
||
namespace EFCore.Cassandra.Benchmarks | ||
{ | ||
internal class Program | ||
{ | ||
private static async Task Main(string[] args) | ||
{ | ||
BenchmarkRunner.Run<InsertData>(); | ||
} | ||
} | ||
} |
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
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