Skip to content

Commit 39d7a39

Browse files
authored
Update to match TechEmpower (#1809)
1 parent 34796da commit 39d7a39

File tree

13 files changed

+63
-120
lines changed

13 files changed

+63
-120
lines changed

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/AsciiString.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/BenchmarkApplication.Plaintext.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
5+
46
namespace PlatformBenchmarks
57
{
68
public partial class BenchmarkApplication
79
{
8-
private readonly static AsciiString _plaintextPreamble =
9-
_http11OK +
10-
_headerServer + _crlf +
11-
_headerContentTypeText + _crlf +
12-
_headerContentLength + _plainTextBody.Length.ToString();
10+
private static ReadOnlySpan<byte> _plaintextPreamble =>
11+
"HTTP/1.1 200 OK\r\n"u8 +
12+
"Server: K\r\n"u8 +
13+
"Content-Type: text/plain\r\n"u8 +
14+
"Content-Length: 13"u8;
1315

1416
private static void PlainText(ref BufferWriter<WriterAdapter> writer)
1517
{

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/BenchmarkApplication.cs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,29 @@
1414

1515
namespace PlatformBenchmarks
1616
{
17-
public partial class BenchmarkApplication
17+
public sealed partial class BenchmarkApplication
1818
{
19-
private readonly static AsciiString _applicationName = "Kestrel Platform-Level Application";
20-
public static AsciiString ApplicationName => _applicationName;
21-
22-
private readonly static AsciiString _crlf = "\r\n";
23-
private readonly static AsciiString _http11OK = "HTTP/1.1 200 OK\r\n";
24-
private readonly static AsciiString _http11NotFound = "HTTP/1.1 404 Not Found\r\n";
25-
private readonly static AsciiString _headerServer = "Server: K";
26-
private readonly static AsciiString _headerContentLength = "Content-Length: ";
27-
private readonly static AsciiString _headerContentLengthZero = "Content-Length: 0";
28-
private readonly static AsciiString _headerContentTypeText = "Content-Type: text/plain";
29-
private readonly static AsciiString _headerContentTypeJson = "Content-Type: application/json";
30-
31-
private readonly static AsciiString _dbPreamble =
32-
_http11OK +
33-
_headerServer + _crlf +
34-
_headerContentTypeJson + _crlf +
35-
_headerContentLength;
36-
37-
private readonly static AsciiString _plainTextBody = "Hello, World!";
38-
private readonly static AsciiString _contentLengthGap = new string(' ', 4);
19+
public static ReadOnlySpan<byte> ApplicationName => "Kestrel Platform-Level Application"u8;
20+
21+
private static ReadOnlySpan<byte> _crlf => "\r\n"u8;
22+
private static ReadOnlySpan<byte> _eoh => "\r\n\r\n"u8; // End Of Headers
23+
private static ReadOnlySpan<byte> _http11OK => "HTTP/1.1 200 OK\r\n"u8;
24+
private static ReadOnlySpan<byte> _http11NotFound => "HTTP/1.1 404 Not Found\r\n"u8;
25+
private static ReadOnlySpan<byte> _headerServer => "Server: K"u8;
26+
private static ReadOnlySpan<byte> _headerContentLength => "Content-Length: "u8;
27+
private static ReadOnlySpan<byte> _headerContentLengthZero => "Content-Length: 0"u8;
28+
private static ReadOnlySpan<byte> _headerContentTypeText => "Content-Type: text/plain"u8;
29+
private static ReadOnlySpan<byte> _headerContentTypeJson => "Content-Type: application/json"u8;
30+
private static ReadOnlySpan<byte> _headerContentTypeHtml => "Content-Type: text/html; charset=UTF-8"u8;
31+
32+
private static ReadOnlySpan<byte> _dbPreamble =>
33+
"HTTP/1.1 200 OK\r\n"u8 +
34+
"Server: K\r\n"u8 +
35+
"Content-Type: application/json\r\n"u8 +
36+
"Content-Length: "u8;
37+
38+
private static ReadOnlySpan<byte> _plainTextBody => "Hello, World!"u8;
39+
private static ReadOnlySpan<byte> _contentLengthGap => " "u8;
3940

4041
public static RawDb RawDb { get; set; }
4142
public static DapperDb DapperDb { get; set; }
@@ -74,15 +75,15 @@ private partial class JsonContext : JsonSerializerContext
7475

7576
public static class Paths
7677
{
77-
public readonly static AsciiString Json = "/json";
78-
public readonly static AsciiString Plaintext = "/plaintext";
79-
public readonly static AsciiString SingleQuery = "/db";
80-
public readonly static AsciiString FortunesRaw = "/fortunes";
81-
public readonly static AsciiString FortunesDapper = "/fortunes/dapper";
82-
public readonly static AsciiString FortunesEf = "/fortunes/ef";
83-
public readonly static AsciiString Updates = "/updates/";
84-
public readonly static AsciiString MultipleQueries = "/queries/";
85-
public readonly static AsciiString Caching = "/cached-worlds/";
78+
public static ReadOnlySpan<byte> Json => "/json"u8;
79+
public static ReadOnlySpan<byte> Plaintext => "/plaintext"u8;
80+
public static ReadOnlySpan<byte> SingleQuery => "/db"u8;
81+
public static ReadOnlySpan<byte> FortunesRaw => "/fortunes"u8;
82+
public static ReadOnlySpan<byte> FortunesDapper => "/fortunes/dapper"u8;
83+
public static ReadOnlySpan<byte> FortunesEf => "/fortunes/ef"u8;
84+
public static ReadOnlySpan<byte> Updates => "/updates/"u8;
85+
public static ReadOnlySpan<byte> MultipleQueries => "/queries/"u8;
86+
public static ReadOnlySpan<byte> Caching => "/cached-worlds/"u8;
8687
}
8788

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

200201
private static void Default(ref BufferWriter<WriterAdapter> writer)
201202
{

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Configuration/AppSettings.cs

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

44
namespace PlatformBenchmarks
55
{
6-
public class AppSettings
6+
public sealed class AppSettings
77
{
88
public string ConnectionString { get; set; }
99

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/BatchUpdateString.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace PlatformBenchmarks
88
{
9-
internal class BatchUpdateString
9+
internal sealed class BatchUpdateString
1010
{
1111
private const int MaxBatch = 500;
1212

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/DapperDb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace PlatformBenchmarks
88
{
9-
public class DapperDb
9+
public sealed class DapperDb
1010
{
1111
private readonly string _connectionString;
1212

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/EfDb.cs

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

88
namespace PlatformBenchmarks
99
{
10-
public class EfDb
10+
public sealed class EfDb
1111
{
1212
private static PooledDbContextFactory<ApplicationDbContext> _dbContextFactory;
1313

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/FortuneEf.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace PlatformBenchmarks
77
{
88
[Table("fortune")]
9-
public class FortuneEf : IComparable<FortuneEf>, IComparable
9+
public sealed class FortuneEf : IComparable<FortuneEf>, IComparable
1010
{
1111
[Column("id")]
1212
public int Id { get; set; }

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/Random.cs

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

88
namespace PlatformBenchmarks
99
{
10-
public class ConcurrentRandom
10+
public sealed class ConcurrentRandom
1111
{
1212
private static int nextSeed = 0;
1313

src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/RawDb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace PlatformBenchmarks
1515
{
16-
public class RawDb
16+
public sealed class RawDb
1717
{
1818
private readonly ConcurrentRandom _random;
1919
private readonly MemoryCache _cache

0 commit comments

Comments
 (0)