Skip to content

Commit fa6f235

Browse files
Merge pull request #358 from MPCoreDeveloper/bench/pk-fixedwidth
bench: add fixed-width variant to the fair PK comparison
2 parents 1b488dc + 16e04dd commit fa6f235

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

  • tests/benchmarks/SharpCoreDB.Benchmarks.Comparative

tests/benchmarks/SharpCoreDB.Benchmarks.Comparative/Program.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,17 @@ static void RunInsertMicroBenchmark()
347347
Console.WriteLine($" SQL/Direct overhead: {(sqlMedian / directMedian):F2}x");
348348
}
349349

350-
static DatabaseConfig BuildConfig(SharpCoreDB.Interfaces.StorageEngineType engineType)
350+
static DatabaseConfig BuildConfig(SharpCoreDB.Interfaces.StorageEngineType engineType, bool fixedWidth = false)
351351
{
352352
return new DatabaseConfig
353353
{
354354
NoEncryptMode = true,
355355
StorageEngineType = engineType,
356+
// The fair PK comparison intentionally isolates the record-layout variable: the legacy
357+
// arm opts out of the AutoFixedWidthRecords default so it measures true variable-length
358+
// records; the fixed-width arm forces FixedWidthRecordLayout.
359+
AutoFixedWidthRecords = !fixedWidth,
360+
FixedWidthRecordLayout = fixedWidth,
356361
UseGroupCommitWal = false,
357362
EnableAdaptiveWalBatching = false,
358363
HighSpeedInsertMode = true,
@@ -840,7 +845,7 @@ data TEXT
840845
/// <c>ExecuteBatchSQL</c> (single transaction). This exercises the PK B-tree fast paths and the
841846
/// recommended usage; the no-PK harness scenario above under-measures the engine on DML.
842847
/// </summary>
843-
static BenchmarkResult RunSharpCoreDBPk(SharpCoreDB.Interfaces.StorageEngineType engineType)
848+
static BenchmarkResult RunSharpCoreDBPk(SharpCoreDB.Interfaces.StorageEngineType engineType, bool fixedWidth = false)
844849
{
845850
var dbPath = Path.Combine(Path.GetTempPath(), $"bench-sharpcoredb-pk-{Guid.NewGuid()}");
846851
var result = new BenchmarkResult();
@@ -852,7 +857,7 @@ static BenchmarkResult RunSharpCoreDBPk(SharpCoreDB.Interfaces.StorageEngineType
852857
var sp = services.BuildServiceProvider();
853858

854859
var factory = sp.GetRequiredService<DatabaseFactory>();
855-
var config = BuildConfig(engineType);
860+
var config = BuildConfig(engineType, fixedWidth);
856861

857862
using var db = (SharpCoreDB.Database)factory.Create(
858863
dbPath: dbPath,
@@ -962,22 +967,29 @@ static void RunPkComparison(SharpCoreDB.Interfaces.StorageEngineType engineType)
962967
Console.WriteLine();
963968
Console.WriteLine($"Engine: {engineLabel}");
964969

965-
Console.WriteLine("━━━ SharpCoreDB (SQL, PK) ━━━");
970+
Console.WriteLine("━━━ SharpCoreDB (SQL, PK, legacy variable-length) ━━━");
966971
var scdb = RunSharpCoreDBPk(engineType);
967972
Console.WriteLine();
968973

974+
Console.WriteLine("━━━ SharpCoreDB (SQL, PK, fixed-width) ━━━");
975+
var scdbFw = RunSharpCoreDBPk(engineType, fixedWidth: true);
976+
Console.WriteLine();
977+
969978
Console.WriteLine("━━━ SQLite (reference) ━━━");
970979
var sqlite = RunSQLite();
971980
Console.WriteLine();
972981

973982
Console.WriteLine("║ Database │ INSERT │ READ │ UPDATE │ DELETE ║");
974983
Console.WriteLine($"║ SharpCoreDB │ {scdb.InsertOpsPerSec,10:N0}{scdb.ReadOpsPerSec,8:N0}{scdb.UpdateOpsPerSec,8:N0}{scdb.DeleteOpsPerSec,8:N0} ║");
984+
Console.WriteLine($"║ SharpCoreDB FW│ {scdbFw.InsertOpsPerSec,10:N0}{scdbFw.ReadOpsPerSec,8:N0}{scdbFw.UpdateOpsPerSec,8:N0}{scdbFw.DeleteOpsPerSec,8:N0} ║");
975985
Console.WriteLine($"║ SQLite │ {sqlite.InsertOpsPerSec,10:N0}{sqlite.ReadOpsPerSec,8:N0}{sqlite.UpdateOpsPerSec,8:N0}{sqlite.DeleteOpsPerSec,8:N0} ║");
976-
Console.WriteLine($"\n UPDATE gap: {sqlite.UpdateOpsPerSec / (double)scdb.UpdateOpsPerSec:F1}x DELETE gap: {sqlite.DeleteOpsPerSec / (double)scdb.DeleteOpsPerSec:F1}x");
986+
Console.WriteLine($"\n UPDATE gap: SQLite vs legacy {sqlite.UpdateOpsPerSec / (double)scdb.UpdateOpsPerSec:F1}x vs fixed-width {sqlite.UpdateOpsPerSec / (double)scdbFw.UpdateOpsPerSec:F1}x");
987+
Console.WriteLine($" DELETE gap: SQLite vs legacy {sqlite.DeleteOpsPerSec / (double)scdb.DeleteOpsPerSec:F1}x vs fixed-width {sqlite.DeleteOpsPerSec / (double)scdbFw.DeleteOpsPerSec:F1}x");
977988

978989
var results = new Dictionary<string, BenchmarkResult>
979990
{
980-
["SharpCoreDB (SQL, PK)"] = scdb,
991+
["SharpCoreDB (SQL, PK, legacy)"] = scdb,
992+
["SharpCoreDB (SQL, PK, fixed-width)"] = scdbFw,
981993
["SQLite"] = sqlite,
982994
};
983995

0 commit comments

Comments
 (0)