Skip to content

Commit

Permalink
aspnetcore: ef compiled queries (TechEmpower#5906)
Browse files Browse the repository at this point in the history
* aspcore: add platform multiple queries

* Add missing console output

* tweak postgresql connectionstring

* aspnetcore: ef compiled queries

Co-authored-by: Stefan Negulescu <tar_the_dark@hotmail.com>
  • Loading branch information
n-stefan and dark-tar authored Jul 29, 2020
1 parent 2302ee4 commit c3a6e97
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions frameworks/CSharp/aspnetcore/Benchmarks/Data/EfDb.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Benchmarks.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Benchmarks.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Options;

namespace Benchmarks.Data
{
Expand All @@ -31,10 +30,7 @@ public Task<World> LoadSingleQueryRow()
{
var id = _random.Next(1, 10001);

// TODO: compiled queries are not supported in EF 3.0-preview7
// return _firstWorldQuery(_dbContext, id);

return _dbContext.World.FirstAsync(w => w.Id == id);
return _firstWorldQuery(_dbContext, id);
}

public async Task<World[]> LoadMultipleQueriesRows(int count)
Expand All @@ -45,10 +41,7 @@ public async Task<World[]> LoadMultipleQueriesRows(int count)
{
var id = _random.Next(1, 10001);

// TODO: compiled queries are not supported in EF 3.0-preview7
// result[i] = await _firstWorldQuery(_dbContext, id);

result[i] = await _dbContext.World.FirstAsync(w => w.Id == id);
result[i] = await _firstWorldQuery(_dbContext, id);
}

return result;
Expand All @@ -64,25 +57,23 @@ public async Task<World[]> LoadMultipleUpdatesRows(int count)
var random = new Random();
int i = 0;

var ids = Enumerable.Range(1,10000).OrderBy(x => random.Next()).Take(count);
var ids = Enumerable.Range(1, 10000).OrderBy(x => random.Next()).Take(count);

foreach(int id in ids)
foreach (int id in ids)
{
// TODO: compiled queries are not supported in EF 3.0-preview7
// var result = await _firstWorldTrackedQuery(_dbContext, id);
var result = await _firstWorldTrackedQuery(_dbContext, id);

var result = await _dbContext.World.AsTracking().FirstAsync(w => w.Id == id);

int oldId = (int) _dbContext.Entry(result).Property("RandomNumber").CurrentValue;
int oldId = (int)_dbContext.Entry(result).Property("RandomNumber").CurrentValue;
int newId;

do{
newId = _random.Next(1, 10001);

do
{
newId = _random.Next(1, 10001);
} while (oldId == newId);

_dbContext.Entry(result).Property("RandomNumber").CurrentValue = newId;
results[i++] = result;

results[i++] = result;
}

await _dbContext.SaveChangesAsync();
Expand All @@ -95,10 +86,12 @@ private static readonly Func<ApplicationDbContext, IAsyncEnumerable<Fortune>> _f

public async Task<List<Fortune>> LoadFortunesRows()
{
var result = await _dbContext.Fortune.ToListAsync();
var result = new List<Fortune>();

// TODO: compiled queries are not supported in EF 3.0-preview7
// await foreach (var element in _fortunesQuery(_dbContext))
await foreach (var element in _fortunesQuery(_dbContext))
{
result.Add(element);
}

result.Add(new Fortune { Message = "Additional fortune added at request time." });
result.Sort();
Expand Down

0 comments on commit c3a6e97

Please sign in to comment.