Skip to content

Update to match TechEmpower #1809

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

Merged
merged 1 commit into from
Mar 17, 2023
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
59 changes: 0 additions & 59 deletions src/BenchmarksApps/TechEmpower/PlatformBenchmarks/AsciiString.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// 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 System;

namespace PlatformBenchmarks
{
public partial class BenchmarkApplication
{
private readonly static AsciiString _plaintextPreamble =
_http11OK +
_headerServer + _crlf +
_headerContentTypeText + _crlf +
_headerContentLength + _plainTextBody.Length.ToString();
private static ReadOnlySpan<byte> _plaintextPreamble =>
"HTTP/1.1 200 OK\r\n"u8 +
"Server: K\r\n"u8 +
"Content-Type: text/plain\r\n"u8 +
"Content-Length: 13"u8;

private static void PlainText(ref BufferWriter<WriterAdapter> writer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@

namespace PlatformBenchmarks
{
public partial class BenchmarkApplication
public sealed partial class BenchmarkApplication
{
private readonly static AsciiString _applicationName = "Kestrel Platform-Level Application";
public static AsciiString ApplicationName => _applicationName;

private readonly static AsciiString _crlf = "\r\n";
private readonly static AsciiString _http11OK = "HTTP/1.1 200 OK\r\n";
private readonly static AsciiString _http11NotFound = "HTTP/1.1 404 Not Found\r\n";
private readonly static AsciiString _headerServer = "Server: K";
private readonly static AsciiString _headerContentLength = "Content-Length: ";
private readonly static AsciiString _headerContentLengthZero = "Content-Length: 0";
private readonly static AsciiString _headerContentTypeText = "Content-Type: text/plain";
private readonly static AsciiString _headerContentTypeJson = "Content-Type: application/json";

private readonly static AsciiString _dbPreamble =
_http11OK +
_headerServer + _crlf +
_headerContentTypeJson + _crlf +
_headerContentLength;

private readonly static AsciiString _plainTextBody = "Hello, World!";
private readonly static AsciiString _contentLengthGap = new string(' ', 4);
public static ReadOnlySpan<byte> ApplicationName => "Kestrel Platform-Level Application"u8;

private static ReadOnlySpan<byte> _crlf => "\r\n"u8;
private static ReadOnlySpan<byte> _eoh => "\r\n\r\n"u8; // End Of Headers
private static ReadOnlySpan<byte> _http11OK => "HTTP/1.1 200 OK\r\n"u8;
private static ReadOnlySpan<byte> _http11NotFound => "HTTP/1.1 404 Not Found\r\n"u8;
private static ReadOnlySpan<byte> _headerServer => "Server: K"u8;
private static ReadOnlySpan<byte> _headerContentLength => "Content-Length: "u8;
private static ReadOnlySpan<byte> _headerContentLengthZero => "Content-Length: 0"u8;
private static ReadOnlySpan<byte> _headerContentTypeText => "Content-Type: text/plain"u8;
private static ReadOnlySpan<byte> _headerContentTypeJson => "Content-Type: application/json"u8;
private static ReadOnlySpan<byte> _headerContentTypeHtml => "Content-Type: text/html; charset=UTF-8"u8;

private static ReadOnlySpan<byte> _dbPreamble =>
"HTTP/1.1 200 OK\r\n"u8 +
"Server: K\r\n"u8 +
"Content-Type: application/json\r\n"u8 +
"Content-Length: "u8;

private static ReadOnlySpan<byte> _plainTextBody => "Hello, World!"u8;
private static ReadOnlySpan<byte> _contentLengthGap => " "u8;

public static RawDb RawDb { get; set; }
public static DapperDb DapperDb { get; set; }
Expand Down Expand Up @@ -74,15 +75,15 @@ private partial class JsonContext : JsonSerializerContext

public static class Paths
{
public readonly static AsciiString Json = "/json";
public readonly static AsciiString Plaintext = "/plaintext";
public readonly static AsciiString SingleQuery = "/db";
public readonly static AsciiString FortunesRaw = "/fortunes";
public readonly static AsciiString FortunesDapper = "/fortunes/dapper";
public readonly static AsciiString FortunesEf = "/fortunes/ef";
public readonly static AsciiString Updates = "/updates/";
public readonly static AsciiString MultipleQueries = "/queries/";
public readonly static AsciiString Caching = "/cached-worlds/";
public static ReadOnlySpan<byte> Json => "/json"u8;
public static ReadOnlySpan<byte> Plaintext => "/plaintext"u8;
public static ReadOnlySpan<byte> SingleQuery => "/db"u8;
public static ReadOnlySpan<byte> FortunesRaw => "/fortunes"u8;
public static ReadOnlySpan<byte> FortunesDapper => "/fortunes/dapper"u8;
public static ReadOnlySpan<byte> FortunesEf => "/fortunes/ef"u8;
public static ReadOnlySpan<byte> Updates => "/updates/"u8;
public static ReadOnlySpan<byte> MultipleQueries => "/queries/"u8;
public static ReadOnlySpan<byte> Caching => "/cached-worlds/"u8;
}

private RequestType _requestType;
Expand Down Expand Up @@ -191,11 +192,11 @@ private static Task Default(PipeWriter pipeWriter)
return Task.CompletedTask;
}
#endif
private readonly static AsciiString _defaultPreamble =
_http11NotFound +
_headerServer + _crlf +
_headerContentTypeText + _crlf +
_headerContentLengthZero;
private static ReadOnlySpan<byte> _defaultPreamble =>
"HTTP/1.1 200 OK\r\n"u8 +
"Server: K"u8 + "\r\n"u8 +
"Content-Type: text/plain"u8 +
"Content-Length: 0"u8;

private static void Default(ref BufferWriter<WriterAdapter> writer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace PlatformBenchmarks
{
public class AppSettings
public sealed class AppSettings
{
public string ConnectionString { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace PlatformBenchmarks
{
internal class BatchUpdateString
internal sealed class BatchUpdateString
{
private const int MaxBatch = 500;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace PlatformBenchmarks
{
public class DapperDb
public sealed class DapperDb
{
private readonly string _connectionString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace PlatformBenchmarks
{
public class EfDb
public sealed class EfDb
{
private static PooledDbContextFactory<ApplicationDbContext> _dbContextFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace PlatformBenchmarks
{
[Table("fortune")]
public class FortuneEf : IComparable<FortuneEf>, IComparable
public sealed class FortuneEf : IComparable<FortuneEf>, IComparable
{
[Column("id")]
public int Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace PlatformBenchmarks
{
public class ConcurrentRandom
public sealed class ConcurrentRandom
{
private static int nextSeed = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace PlatformBenchmarks
{
public class RawDb
public sealed class RawDb
{
private readonly ConcurrentRandom _random;
private readonly MemoryCache _cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static class DateHeader

static DateHeader()
{
var utf8 = Encoding.ASCII.GetBytes("\r\nDate: ").AsSpan();
var utf8 = "\r\nDate: "u8;

utf8.CopyTo(s_headerBytesMaster);
utf8.CopyTo(s_headerBytesScratch);
Expand Down Expand Up @@ -61,9 +61,7 @@ private static void SetDateValues(DateTimeOffset value)
throw new Exception("date time format failed");
}
Debug.Assert(written == dateTimeRLength);
var temp = s_headerBytesMaster;
s_headerBytesMaster = s_headerBytesScratch;
s_headerBytesScratch = temp;
(s_headerBytesScratch, s_headerBytesMaster) = (s_headerBytesMaster, s_headerBytesScratch);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class HttpApplicationConnectionBuilderExtensions
}
}

public class HttpApplication<TConnection> where TConnection : IHttpConnection, new()
public sealed class HttpApplication<TConnection> where TConnection : IHttpConnection, new()
{
public Task ExecuteAsync(ConnectionContext connection)
{
Expand Down
19 changes: 10 additions & 9 deletions src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand All @@ -20,17 +21,17 @@ public static async Task Main(string[] args)
{
Args = args;

Console.WriteLine(BenchmarkApplication.ApplicationName);
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.ApplicationName));
#if !DATABASE
Console.WriteLine(BenchmarkApplication.Paths.Plaintext);
Console.WriteLine(BenchmarkApplication.Paths.Json);
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.Plaintext));
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.Json));
#else
Console.WriteLine(BenchmarkApplication.Paths.FortunesRaw);
Console.WriteLine(BenchmarkApplication.Paths.FortunesDapper);
Console.WriteLine(BenchmarkApplication.Paths.FortunesEf);
Console.WriteLine(BenchmarkApplication.Paths.SingleQuery);
Console.WriteLine(BenchmarkApplication.Paths.Updates);
Console.WriteLine(BenchmarkApplication.Paths.MultipleQueries);
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.FortunesRaw));
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.FortunesDapper));
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.FortunesEf));
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.SingleQuery));
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.Updates));
Console.WriteLine(Encoding.UTF8.GetString(BenchmarkApplication.Paths.MultipleQueries));
#endif
DateHeader.SyncDateTimer();

Expand Down