Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.
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
57 changes: 48 additions & 9 deletions frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,70 @@
<AssemblyTitle>GenHTTP Benchmarks</AssemblyTitle>
<Description>Test suite to be executed with TechEmpower FrameworkBenchmarks.</Description>

<DefineConstants>$(DefineConstants);$(GENHTTP_ENGINE_NAME)</DefineConstants>

<EngineName>$(GENHTTP_ENGINE_NAME)</EngineName>
<ServerGarbageCollection>true</ServerGarbageCollection>
<TieredPGO>true</TieredPGO>

<EnableDefaultCompileItems>false</EnableDefaultCompileItems>

</PropertyGroup>

<ItemGroup>

<Compile Include="**\*.cs" Exclude="Program.*.cs" />

<None Remove="Resources\Fortunes.html" />
<None Remove="Resources\Template.html" />

<EmbeddedResource Include="Resources\Template.html" />

</ItemGroup>

<ItemGroup Condition="'$(EngineName)' == 'Internal'">

<Compile Include="Program.Internal.cs" />

<ItemGroup>
<EmbeddedResource Include="Resources\Template.html" />
<PackageReference Include="GenHTTP.Core" Version="10.4.0" />

</ItemGroup>

<ItemGroup>
<ItemGroup Condition="'$(EngineName)' == 'Kestrel'">

<Compile Include="Program.Kestrel.cs" />

<PackageReference Include="GenHTTP.Core.Kestrel" Version="10.4.0" />

</ItemGroup>

<ItemGroup Condition="'$(EngineName)' == 'Wired'">

<Compile Include="Program.Wired.cs" />

<PackageReference Include="$(GENHTTP_ENGINE_PACKAGE)" Version="10.2.0" />
<PackageReference Include="Wired.IO" Version="10.1.3" />

<PackageReference Include="GenHTTP.Adapters.WiredIO" Version="10.4.0" />

</ItemGroup>

<ItemGroup Condition="'$(EngineName)' == 'Unhinged'">

<Compile Include="Program.Unhinged.cs" />

<PackageReference Include="Unhinged" Version="9.0.7" />

<PackageReference Include="Unhinged.GenHttp.Experimental" Version="10.4.0" />

</ItemGroup>

<ItemGroup>

<PackageReference Include="GenHTTP.Modules.Webservices" Version="10.2.0" />
<PackageReference Include="GenHTTP.Modules.Webservices" Version="10.4.0" />

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
<PackageReference Include="Npgsql" Version="10.0.1" />

<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.2" />

</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions frameworks/CSharp/genhttp/Benchmarks/Model/Database.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Benchmarks.Model;

using Npgsql;

public static class Database
{

public static readonly NpgsqlDataSource DataSource = BuildDataSource();

private static NpgsqlDataSource BuildDataSource()
{
var connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION");

return new NpgsqlSlimDataSourceBuilder(connectionString).EnableArrays().Build();
}

}
43 changes: 0 additions & 43 deletions frameworks/CSharp/genhttp/Benchmarks/Model/DatabaseContext.cs

This file was deleted.

80 changes: 80 additions & 0 deletions frameworks/CSharp/genhttp/Benchmarks/Model/FortuneMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections;
using Cottle;

namespace Benchmarks.Model;

public readonly struct FortuneMap : IMap
{
private readonly int _id;
private readonly string _message;

public FortuneMap(int id, string message)
{
_id = id;
_message = message;
}

public Value this[Value key] => TryGet(key, out var value) ? value : Value.Undefined;

public int Count => 2;

public bool Contains(Value key)
{
var keyStr = key.AsString;
return keyStr == "id" || keyStr == "message";
}

public bool TryGet(Value key, out Value value)
{
var keyStr = key.AsString;
if (keyStr == "id")
{
value = _id;
return true;
}
if (keyStr == "message")
{
value = _message;
return true;
}

value = Value.Undefined;
return false;
}

public int CompareTo(IMap other)
{
if (other == null) return 1;

if (other.TryGet("id", out var otherId))
{
return _id.CompareTo(otherId.AsNumber);
}

return Count.CompareTo(other.Count);
}

public bool Equals(IMap other)
{
if (other == null || other.Count != Count)
return false;

return other.TryGet("id", out var otherId) &&
other.TryGet("message", out var otherMsg) &&
_id == (int)otherId.AsNumber &&
_message == otherMsg.AsString;
}

public IEnumerator<KeyValuePair<Value, Value>> GetEnumerator()
{
yield return new KeyValuePair<Value, Value>("id", _id);
yield return new KeyValuePair<Value, Value>("message", _message);
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public override bool Equals(object obj) => obj is IMap map && Equals(map);

public override int GetHashCode() => HashCode.Combine(_id, _message);

}
9 changes: 9 additions & 0 deletions frameworks/CSharp/genhttp/Benchmarks/Program.Internal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Benchmarks;

using GenHTTP.Engine.Internal;

var project = Project.Create();

return await Host.Create()
.Handler(project)
.RunAsync();
9 changes: 9 additions & 0 deletions frameworks/CSharp/genhttp/Benchmarks/Program.Kestrel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Benchmarks;

using GenHTTP.Engine.Kestrel;

var project = Project.Create();

return await Host.Create()
.Handler(project)
.RunAsync();
17 changes: 17 additions & 0 deletions frameworks/CSharp/genhttp/Benchmarks/Program.Unhinged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Benchmarks;

using Unhinged;
using Unhinged.GenHttp.Experimental;

var project = Project.Create();

UnhingedEngine.CreateBuilder()
.SetPort(8080)
.SetNWorkersSolver(() => Environment.ProcessorCount)
.SetBacklog(16384)
.SetMaxEventsPerWake(512)
.SetMaxNumberConnectionsPerWorker(1024)
.SetSlabSizes(32 * 1024, 16 * 1024)
.Map(project)
.Build()
.Run();
14 changes: 14 additions & 0 deletions frameworks/CSharp/genhttp/Benchmarks/Program.Wired.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Benchmarks;

using GenHTTP.Adapters.WiredIO;

using Wired.IO.App;

var project = Project.Create();

await WiredApp.CreateExpressBuilder()
.Port(8080)
.MapGenHttp("*", project)
.Build()
.RunAsync();

26 changes: 0 additions & 26 deletions frameworks/CSharp/genhttp/Benchmarks/Program.cs

This file was deleted.

31 changes: 31 additions & 0 deletions frameworks/CSharp/genhttp/Benchmarks/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Benchmarks.Tests;
using Benchmarks.Utilities;

using GenHTTP.Api.Content;

using GenHTTP.Modules.IO;
using GenHTTP.Modules.Layouting;
using GenHTTP.Modules.Reflection;
using GenHTTP.Modules.Webservices;

namespace Benchmarks;

public static class Project
{

public static IHandlerBuilder Create()
{
var mode = ExecutionMode.Auto;

return Layout.Create()
.Add("plaintext", Content.From(Resource.FromString("Hello, World!")))
.Add("json", new JsonHandler())
.Add("fortunes", new FortuneHandler())
.AddService<DbResource>("db", mode: mode)
.AddService<QueryResource>("queries", mode: mode)
.AddService<UpdateResource>("updates", mode: mode)
.AddService<CacheResource>("cached-worlds", mode: mode)
.Add(ServerHeader.Create());
}

}
Loading
Loading