Skip to content
Open
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
13 changes: 13 additions & 0 deletions Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BenchmarkDotNet.Configs;
using Comparisons.SQLiteVSDoublets.Model;
using Comparisons.SQLiteVSDoublets.SQLite;
using Comparisons.SQLiteVSDoublets.SystemDataSQLite;
using Comparisons.SQLiteVSDoublets.Doublets;

namespace Comparisons.SQLiteVSDoublets
Expand All @@ -22,13 +23,15 @@ private class Config : ManualConfig
[Params(1000, 10000, 100000)]
public int N;
private SQLiteTestRun _sqliteTestRun;
private SystemDataSQLiteTestRun _systemDataSqliteTestRun;
private DoubletsTestRun _doubletsTestRun;

[GlobalSetup]
public void Setup()
{
BlogPosts.GenerateData(N);
_sqliteTestRun = new SQLiteTestRun("test.db");
_systemDataSqliteTestRun = new SystemDataSQLiteTestRun("test-systemdata.db");
_doubletsTestRun = new DoubletsTestRun("test.links");
}

Expand All @@ -42,6 +45,16 @@ public void SQLiteOutput()
File.WriteAllText(Path.Combine(SizeAfterCreationColumn.DbSizeOutputFolder, $"disk-size.sqlite.{N}.txt"), _sqliteTestRun.Results.DbSizeAfterCreation.ToString());
}

[Benchmark]
public void SystemDataSQLite() => _systemDataSqliteTestRun.Run();

[IterationCleanup(Target = "SystemDataSQLite")]
public void SystemDataSQLiteOutput()
{
Directory.CreateDirectory(SizeAfterCreationColumn.DbSizeOutputFolder);
File.WriteAllText(Path.Combine(SizeAfterCreationColumn.DbSizeOutputFolder, $"disk-size.systemdata-sqlite.{N}.txt"), _systemDataSqliteTestRun.Results.DbSizeAfterCreation.ToString());
}

[Benchmark]
public void Doublets() => _doubletsTestRun.Run();

Expand Down
3 changes: 2 additions & 1 deletion Comparisons.SQLiteVSDoublets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.9" />
<PackageReference Include="Platform.Diagnostics" Version="0.1.0" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Release'">
Expand Down
4 changes: 4 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using Comparisons.SQLiteVSDoublets.SQLite;
using Comparisons.SQLiteVSDoublets.Doublets;
using Comparisons.SQLiteVSDoublets.Experiments;
using Comparisons.SQLiteVSDoublets.Model;
using BenchmarkDotNet.Running;

Expand All @@ -18,6 +19,9 @@ class Program
/// </summary>
static void Main()
{
// Test System.Data.SQLite implementation
TestSystemDataSQLite.RunTest();

BenchmarkRunner.Run<Benchmarks>();
// Use this method if you need full control over the execution.
//Run();
Expand Down
146 changes: 146 additions & 0 deletions SystemDataSQLite/SystemDataSQLiteTestRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using Comparisons.SQLiteVSDoublets.Model;

namespace Comparisons.SQLiteVSDoublets.SystemDataSQLite
{
/// <summary>
/// <para>
/// Represents the System.Data.SQLite test run.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="TestRun"/>
public class SystemDataSQLiteTestRun : TestRun
{
/// <summary>
/// <para>
/// The connection string.
/// </para>
/// <para></para>
/// </summary>
private readonly string _connectionString;

/// <summary>
/// <para>
/// Initializes a new <see cref="SystemDataSQLiteTestRun"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="dbFilename">
/// <para>A db filename.</para>
/// <para></para>
/// </param>
public SystemDataSQLiteTestRun(string dbFilename) : base(dbFilename)
{
_connectionString = $"Data Source={dbFilename};Version=3;";
}

/// <summary>
/// <para>
/// Prepares this instance.
/// </para>
/// <para></para>
/// </summary>
public override void Prepare()
{
using var connection = new SQLiteConnection(_connectionString);
connection.Open();

const string createTableQuery = @"
CREATE TABLE IF NOT EXISTS BlogPosts (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Title TEXT NOT NULL UNIQUE,
Content TEXT NOT NULL,
PublicationDateTime TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
)";

using var command = new SQLiteCommand(createTableQuery, connection);
command.ExecuteNonQuery();
}

/// <summary>
/// <para>
/// Creates the list.
/// </para>
/// <para></para>
/// </summary>
public override void CreateList()
{
using var connection = new SQLiteConnection(_connectionString);
connection.Open();

using var transaction = connection.BeginTransaction();

const string insertQuery = @"
INSERT INTO BlogPosts (Title, Content, PublicationDateTime)
VALUES (@Title, @Content, @PublicationDateTime)";

using var command = new SQLiteCommand(insertQuery, connection, transaction);

var titleParam = command.Parameters.Add("@Title", DbType.String);
var contentParam = command.Parameters.Add("@Content", DbType.String);
var dateParam = command.Parameters.Add("@PublicationDateTime", DbType.String);

foreach (var blogPost in BlogPosts.List)
{
titleParam.Value = blogPost.Title;
contentParam.Value = blogPost.Content;
dateParam.Value = blogPost.PublicationDateTime.ToString("yyyy-MM-dd HH:mm:ss");

command.ExecuteNonQuery();
}

transaction.Commit();
}

/// <summary>
/// <para>
/// Reads the list.
/// </para>
/// <para></para>
/// </summary>
public override void ReadList()
{
using var connection = new SQLiteConnection(_connectionString);
connection.Open();

const string selectQuery = @"SELECT Id, Title, Content, PublicationDateTime FROM BlogPosts";

using var command = new SQLiteCommand(selectQuery, connection);
using var reader = command.ExecuteReader();

while (reader.Read())
{
var blogPost = new BlogPost
{
Id = reader.GetInt32("Id"),
Title = reader.GetString("Title"),
Content = reader.GetString("Content"),
PublicationDateTime = DateTime.Parse(reader.GetString("PublicationDateTime"))
};

ReadBlogPosts.Add(blogPost);
}
}

/// <summary>
/// <para>
/// Deletes the list.
/// </para>
/// <para></para>
/// </summary>
public override void DeleteList()
{
using var connection = new SQLiteConnection(_connectionString);
connection.Open();

const string deleteQuery = @"DELETE FROM BlogPosts";

using var command = new SQLiteCommand(deleteQuery, connection);
command.ExecuteNonQuery();
}
}
}
25 changes: 25 additions & 0 deletions TestSystemDataSQLite.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<StartupObject>Comparisons.SQLiteVSDoublets.TestApp.TestProgram</StartupObject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.9" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
<PackageReference Include="Platform.Diagnostics" Version="0.1.0" />
<PackageReference Include="Platform.IO" Version="0.5.1" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Program.cs" />
<Compile Remove="Benchmarks.cs" />
<Compile Remove="SizeAfterCreationColumn.cs" />
<Compile Remove="Doublets\**" />
<Compile Remove="cpp\**" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions experiments/TestProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using Comparisons.SQLiteVSDoublets.Experiments;

namespace Comparisons.SQLiteVSDoublets.TestApp
{
class TestProgram
{
static void Main()
{
Console.WriteLine("Testing System.Data.SQLite integration...");
TestSystemDataSQLite.RunTest();
Console.WriteLine("Test completed.");
}
}
}
79 changes: 79 additions & 0 deletions experiments/TestSystemDataSQLite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.IO;
using Comparisons.SQLiteVSDoublets.Model;
using Comparisons.SQLiteVSDoublets.SQLite;
using Comparisons.SQLiteVSDoublets.SystemDataSQLite;

namespace Comparisons.SQLiteVSDoublets.Experiments
{
/// <summary>
/// <para>
/// Simple test to verify System.Data.SQLite implementation works.
/// </para>
/// <para></para>
/// </summary>
public class TestSystemDataSQLite
{
public static void RunTest()
{
Console.WriteLine("Testing System.Data.SQLite implementation...");

// Generate test data
const int testDataSize = 10;
BlogPosts.GenerateData(testDataSize);

// Test System.Data.SQLite implementation
var systemDataSqliteTestRun = new SystemDataSQLiteTestRun("test-systemdata.db");

try
{
// Clean up any existing test file
if (File.Exists("test-systemdata.db"))
File.Delete("test-systemdata.db");

systemDataSqliteTestRun.Run();

Console.WriteLine("✓ System.Data.SQLite test completed successfully");
Console.WriteLine($"Results: {systemDataSqliteTestRun.Results}");
}
catch (Exception ex)
{
Console.WriteLine($"✗ System.Data.SQLite test failed: {ex.Message}");
Console.WriteLine($"Stack trace: {ex.StackTrace}");
}

// Test Entity Framework SQLite implementation for comparison
var efSqliteTestRun = new SQLiteTestRun("test-ef.db");

try
{
// Clean up any existing test file
if (File.Exists("test-ef.db"))
File.Delete("test-ef.db");

efSqliteTestRun.Run();

Console.WriteLine("✓ Entity Framework SQLite test completed successfully");
Console.WriteLine($"Results: {efSqliteTestRun.Results}");
}
catch (Exception ex)
{
Console.WriteLine($"✗ Entity Framework SQLite test failed: {ex.Message}");
Console.WriteLine($"Stack trace: {ex.StackTrace}");
}

// Clean up test files
try
{
if (File.Exists("test-systemdata.db"))
File.Delete("test-systemdata.db");
if (File.Exists("test-ef.db"))
File.Delete("test-ef.db");
}
catch
{
// Ignore cleanup errors
}
}
}
}
Binary file added test-ef.db-shm
Binary file not shown.
Binary file added test-ef.db-wal
Binary file not shown.
Loading