Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr2965v2 #2990

Merged
merged 4 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions samples/core/Benchmarks/AverageBlogRanking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ namespace Benchmarks
[MemoryDiagnoser]
public class AverageBlogRanking
{
public const int NumBlogs = 1000;
[Params(1000)]
public int NumBlogs; // number of records to write [once], and read [each pass]

[GlobalSetup]
public void Setup()
{
using var context = new BloggingContext();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.SeedData();
context.SeedData(NumBlogs);
}

#region LoadEntities
Expand All @@ -35,7 +36,7 @@ public double LoadEntities()
count++;
}

return sum / count;
return (double)sum / count;
}
#endregion

Expand All @@ -52,7 +53,7 @@ public double LoadEntitiesNoTracking()
count++;
}

return sum / count;
return (double)sum / count;
}
#endregion

Expand All @@ -69,7 +70,7 @@ public double ProjectOnlyRanking()
count++;
}

return sum / count;
return (double)sum / count;
}
#endregion

Expand All @@ -89,10 +90,10 @@ public class BloggingContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Blogging;Integrated Security=True");

public void SeedData()
public void SeedData(int numblogs)
{
Blogs.AddRange(
Enumerable.Range(0, NumBlogs).Select(i => new Blog
Enumerable.Range(0, numblogs).Select(i => new Blog
{
Name = $"Blog{i}",
Url = $"blog{i}.blogs.net",
Expand Down
7 changes: 4 additions & 3 deletions samples/core/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Optimize>true</Optimize>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="5.0.1" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions samples/core/Benchmarks/DynamicallyConstructedQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DynamicallyConstructedQueries
private int _blogNumber;

[GlobalSetup]
public void GlobalSetup()
public static void GlobalSetup()
{
using var context = new BloggingContext();
context.Database.EnsureDeleted();
Expand All @@ -30,7 +30,7 @@ public int WithConstant()
{
return GetBlogCount("blog" + Interlocked.Increment(ref _blogNumber));

int GetBlogCount(string url)
static int GetBlogCount(string url)
{
using var context = new BloggingContext();

Expand Down
8 changes: 4 additions & 4 deletions samples/core/Benchmarks/Inheritance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Inheritance
[Params(5000)]
public int RowsPerEntityType { get; set; }

[GlobalSetup(Target=nameof(TPH))]
[GlobalSetup(Target = nameof(TPH))]
public void SetupTPH()
{
Console.WriteLine("Setting up database...");
Expand All @@ -26,7 +26,7 @@ public void SetupTPH()
Console.WriteLine("Setup complete.");
}

[GlobalSetup(Target=nameof(TPT))]
[GlobalSetup(Target = nameof(TPT))]
public void SetupTPT()
{
Console.WriteLine("Setting up database...");
Expand All @@ -38,15 +38,15 @@ public void SetupTPT()
}

[Benchmark]
public List<Root> TPH()
public static List<Root> TPH()
{
using var context = new TPHContext();

return context.Roots.ToList();
}

[Benchmark]
public List<Root> TPT()
public static List<Root> TPT()
{
using var context = new TPTContext();

Expand Down
3 changes: 1 addition & 2 deletions samples/core/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Benchmarks
{
public class Program
{
public static void Main(string[] args)
=> BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
public static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
8 changes: 4 additions & 4 deletions samples/core/Benchmarks/QueryTrackingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ public void Setup()
using var context = new BloggingContext();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.SeedData(NumBlogs, NumPostsPerBlog);
BloggingContext.SeedData(NumBlogs, NumPostsPerBlog);
Console.WriteLine("Setup complete.");
}

[Benchmark(Baseline = true)]
public List<Post> AsTracking()
public static List<Post> AsTracking()
{
using var context = new BloggingContext();

return context.Posts.AsTracking().Include(p => p.Blog).ToList();
}

[Benchmark]
public List<Post> AsNoTracking()
public static List<Post> AsNoTracking()
{
using var context = new BloggingContext();

Expand All @@ -53,7 +53,7 @@ public class BloggingContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Blogging;Integrated Security=True");

public void SeedData(int numBlogs, int numPostsPerBlog)
public static void SeedData(int numBlogs, int numPostsPerBlog)
{
using var context = new BloggingContext();
context.AddRange(
Expand Down