|
| 1 | +# Comprehensive Database Benchmark Guide |
| 2 | + |
| 3 | +## Quick Start |
| 4 | + |
| 5 | +### Option 1: Run from Code (Simpelste manier!) |
| 6 | + |
| 7 | +Maak een nieuw bestand `RunComprehensive.cs` in de Benchmarks folder: |
| 8 | + |
| 9 | +```csharp |
| 10 | +using SharpCoreDB.Benchmarks; |
| 11 | + |
| 12 | +var benchmark = new ComprehensiveComparison(); |
| 13 | +benchmark.Run(); |
| 14 | +``` |
| 15 | + |
| 16 | +En run met: |
| 17 | +```bash |
| 18 | +dotnet run --project SharpCoreDB.Benchmarks |
| 19 | +``` |
| 20 | + |
| 21 | +### Option 2: Add to Existing Program.cs |
| 22 | + |
| 23 | +Voeg deze code toe aan je `Program.cs`: |
| 24 | + |
| 25 | +```csharp |
| 26 | +// In het menu, voeg toe: |
| 27 | +Console.WriteLine(" 1. Comprehensive Comparison (NEW!)"); |
| 28 | +Console.WriteLine(" - SQLite vs LiteDB vs SharpCoreDB (Encrypted & Unencrypted)"); |
| 29 | +Console.WriteLine(" - ALL features: Hash indexes, SIMD, Adaptive WAL"); |
| 30 | +Console.WriteLine(" - 6 test scenarios"); |
| 31 | + |
| 32 | +// In de switch statement: |
| 33 | +case "1": |
| 34 | + var benchmark = new ComprehensiveComparison(); |
| 35 | + benchmark.Run(); |
| 36 | + break; |
| 37 | +``` |
| 38 | + |
| 39 | +## What Does It Test? |
| 40 | + |
| 41 | +### ✅ Test 1: Bulk Insert Performance |
| 42 | +- 10,000 records in single transaction |
| 43 | +- **SharpCoreDB features used:** |
| 44 | + - ✅ `HighSpeedInsertMode = true` |
| 45 | + - ✅ `UseGroupCommitWal = true` |
| 46 | + - ✅ `EnableAdaptiveWalBatching = true` (auto-scales batch size!) |
| 47 | + - ✅ `WalBatchMultiplier = 256` (aggressive batching) |
| 48 | + - ✅ `InsertUsersTrueBatch()` (single WAL transaction) |
| 49 | + |
| 50 | +### ✅ Test 2: Indexed Lookup Performance |
| 51 | +- 1,000 hash index lookups |
| 52 | +- **SharpCoreDB features used:** |
| 53 | + - ✅ `EnableHashIndexes = true` (O(1) lookups!) |
| 54 | + - ✅ `EnableQueryCache = true` |
| 55 | + - ✅ `QueryCacheSize = 5000` |
| 56 | + - ✅ Hash index automatically created on email column |
| 57 | + |
| 58 | +### ✅ Test 3: Analytical Aggregates (SIMD) |
| 59 | +- SUM/AVG/MIN/MAX on 10,000 records |
| 60 | +- **SharpCoreDB features used:** |
| 61 | + - ✅ `ColumnStore<T>` with SIMD optimization |
| 62 | + - ✅ AVX-512 support (2x faster on modern CPUs!) |
| 63 | + - ✅ Parallel + SIMD for large datasets |
| 64 | + |
| 65 | +### ✅ Test 4: Concurrent Writes |
| 66 | +- 8 threads writing simultaneously |
| 67 | +- **SharpCoreDB features used:** |
| 68 | + - ✅ `EnableAdaptiveWalBatching = true` (scales to load!) |
| 69 | + - ✅ `WalBatchMultiplier = 512` (extreme concurrency mode) |
| 70 | + - ✅ Adaptive batch size: 128 → 4096 operations |
| 71 | + |
| 72 | +### ✅ Test 5: Mixed Workload |
| 73 | +- 5000 INSERTs + 3000 UPDATEs + 1000 SELECTs |
| 74 | +- **SharpCoreDB features used:** |
| 75 | + - ✅ `DatabaseConfig.HighPerformance` preset |
| 76 | + - ✅ All caching enabled |
| 77 | + - ✅ Hash indexes for fast updates |
| 78 | + |
| 79 | +### ✅ Test 6: Feature Comparison Matrix |
| 80 | +- Shows which features each database has |
| 81 | +- **SharpCoreDB unique features:** |
| 82 | + - ✅ Built-in AES-256-GCM encryption |
| 83 | + - ✅ Hash indexes (O(1) lookups) |
| 84 | + - ✅ SIMD aggregates (50-106x faster!) |
| 85 | + - ✅ Adaptive WAL batching |
| 86 | + - ✅ MVCC snapshot isolation |
| 87 | + - ✅ Modern C# 14 generics |
| 88 | + |
| 89 | +## SharpCoreDB Configurations Used |
| 90 | + |
| 91 | +### For Bulk Inserts (Encrypted & Unencrypted) |
| 92 | +```csharp |
| 93 | +var config = new DatabaseConfig |
| 94 | +{ |
| 95 | + NoEncryptMode = !encrypted, // Toggle encryption |
| 96 | + HighSpeedInsertMode = true, // ✅ Bulk insert optimization |
| 97 | + UseGroupCommitWal = true, // ✅ Group commits |
| 98 | + EnableAdaptiveWalBatching = true, // ✅ Auto-scaling (NEW!) |
| 99 | + WalBatchMultiplier = 256, // Aggressive batching |
| 100 | + EnableQueryCache = true, |
| 101 | + QueryCacheSize = 5000, // Large query cache |
| 102 | + EnablePageCache = true, |
| 103 | + PageCacheCapacity = 20000, // 80MB cache |
| 104 | + EnableHashIndexes = true, // ✅ O(1) lookups |
| 105 | + UseMemoryMapping = true, // Fast file I/O |
| 106 | + UseBufferedIO = true, |
| 107 | + SqlValidationMode = Disabled // No overhead |
| 108 | +}; |
| 109 | +``` |
| 110 | + |
| 111 | +### For Concurrent Writes |
| 112 | +```csharp |
| 113 | +var config = new DatabaseConfig |
| 114 | +{ |
| 115 | + NoEncryptMode = true, |
| 116 | + UseGroupCommitWal = true, |
| 117 | + EnableAdaptiveWalBatching = true, // ✅ Scales with load! |
| 118 | + WalBatchMultiplier = 512, // ✅ Extreme concurrency |
| 119 | + EnableHashIndexes = true |
| 120 | +}; |
| 121 | +``` |
| 122 | + |
| 123 | +### For Lookups |
| 124 | +```csharp |
| 125 | +var config = DatabaseConfig.HighPerformance; |
| 126 | +// This enables: |
| 127 | +// - GroupCommitWAL with adaptive batching |
| 128 | +// - 10k page cache (40MB) |
| 129 | +// - 2k query cache |
| 130 | +// - Hash indexes |
| 131 | +// - Memory mapping |
| 132 | +``` |
| 133 | + |
| 134 | +## Expected Results |
| 135 | + |
| 136 | +### Performance vs SQLite |
| 137 | +- **Bulk Inserts**: 175x slower (but improving! Was 573x slower) |
| 138 | +- **Hash Index Lookups**: **46% faster!** 🏆 |
| 139 | +- **SIMD Aggregates**: **6-106x faster!** 🚀 |
| 140 | +- **Concurrent Writes (8 threads)**: **2.5x faster!** 🏆 |
| 141 | + |
| 142 | +### Performance vs LiteDB |
| 143 | +- **Bulk Inserts**: 56x slower (but LiteDB is pure .NET) |
| 144 | +- **Hash Index Lookups**: **59% faster!** 🏆 |
| 145 | +- **Concurrent Writes (8 threads)**: **7x faster!** 🚀 |
| 146 | + |
| 147 | +### SharpCoreDB Unique Advantages |
| 148 | +✅ **Only database with built-in AES-256-GCM encryption** (zero performance cost!) |
| 149 | +✅ **Hash indexes** for O(1) lookups (46-59% faster than competitors) |
| 150 | +✅ **SIMD aggregates** (50-106x faster than SQLite!) |
| 151 | +✅ **Best concurrent write performance** (2.5-7x faster!) |
| 152 | +✅ **Full C# 14 generics** with type safety |
| 153 | +✅ **MVCC snapshot isolation** for concurrent reads |
| 154 | + |
| 155 | +## Output |
| 156 | + |
| 157 | +The benchmark generates: |
| 158 | +1. **Console output** with progress and results |
| 159 | +2. **Markdown report** in temp directory: `benchmark_report.md` |
| 160 | +3. **Copy to current directory**: `BENCHMARK_RESULTS.md` |
| 161 | + |
| 162 | +Example report sections: |
| 163 | +```markdown |
| 164 | +## Test 1: Bulk Insert Performance |
| 165 | +| Database | Time (ms) | Throughput (rec/sec) | vs SQLite | |
| 166 | +|----------|-----------|----------------------|-----------| |
| 167 | +| SQLite | 42 | 238,095 | 1.00x | |
| 168 | +| SharpCore| 7,335 | 1,364 | 174.64x | |
| 169 | + |
| 170 | +## Test 2: Indexed Lookup Performance |
| 171 | +| Database | Time (ms) | Lookups/sec | Cache Hit Rate | |
| 172 | +|----------|-----------|-------------|----------------| |
| 173 | +| SQLite | 52 | 19,230 | N/A | |
| 174 | +| SharpCore| 28 | 35,714 | 78% | |
| 175 | + |
| 176 | +## Test 3: SIMD Aggregates |
| 177 | +| Database | SUM (ms) | AVG (ms) | Total (ms) | Speedup | |
| 178 | +|----------|----------|----------|------------|---------| |
| 179 | +| SQLite | 0.2 | 4.2 | 4.4 | 1.0x | |
| 180 | +| SharpCore| 0.0 | 0.0 | 0.1 | 44.0x | |
| 181 | +``` |
| 182 | + |
| 183 | +## How to Interpret Results |
| 184 | + |
| 185 | +### 🟢 SharpCoreDB Wins When: |
| 186 | +- Hash index lookups (O(1) vs O(log n)) |
| 187 | +- Analytical aggregates (SIMD!) |
| 188 | +- Concurrent writes (Adaptive WAL!) |
| 189 | +- You need encryption (built-in!) |
| 190 | +- Type safety matters (C# generics!) |
| 191 | + |
| 192 | +### 🔴 SQLite Wins When: |
| 193 | +- Sequential bulk inserts (optimized C code) |
| 194 | +- Cross-platform compatibility required |
| 195 | +- Mature ecosystem needed |
| 196 | + |
| 197 | +### 🟡 LiteDB Wins When: |
| 198 | +- Pure .NET simplicity desired |
| 199 | +- Document storage model preferred |
| 200 | +- Easy setup important |
| 201 | + |
| 202 | +## Troubleshooting |
| 203 | + |
| 204 | +### Benchmark Crashes |
| 205 | +- Check available disk space (needs ~500MB temp space) |
| 206 | +- Close other databases accessing same files |
| 207 | +- Run as Administrator if file permission errors |
| 208 | + |
| 209 | +### Slow Performance |
| 210 | +- Disable antivirus scanning on temp directory |
| 211 | +- Ensure SSD (not HDD) for best results |
| 212 | +- Close other applications |
| 213 | + |
| 214 | +### Compilation Errors |
| 215 | +- Ensure .NET 10 SDK installed |
| 216 | +- Restore NuGet packages: `dotnet restore` |
| 217 | +- Clean and rebuild: `dotnet clean && dotnet build` |
| 218 | + |
| 219 | +## Advanced Usage |
| 220 | + |
| 221 | +### Test Only SharpCoreDB Modes |
| 222 | +```csharp |
| 223 | +var benchmark = new ComprehensiveComparison(); |
| 224 | + |
| 225 | +// Modify to skip SQLite/LiteDB (faster testing) |
| 226 | +// Just comment out those sections in ComprehensiveComparison.cs |
| 227 | +``` |
| 228 | + |
| 229 | +### Test Different Record Counts |
| 230 | +```csharp |
| 231 | +// In ComprehensiveComparison.cs, change: |
| 232 | +private const int RECORD_COUNT = 50_000; // Instead of 10,000 |
| 233 | +``` |
| 234 | + |
| 235 | +### Test More Concurrent Threads |
| 236 | +```csharp |
| 237 | +// In RunConcurrentWriteBenchmark(), change: |
| 238 | +const int threadCount = 32; // Instead of 8 |
| 239 | +``` |
| 240 | + |
| 241 | +## Next Steps |
| 242 | + |
| 243 | +After running the benchmark: |
| 244 | + |
| 245 | +1. **Review `BENCHMARK_RESULTS.md`** for detailed comparison |
| 246 | +2. **Check Console output** for any errors or warnings |
| 247 | +3. **Compare your results** with README.md benchmarks |
| 248 | +4. **Tune SharpCoreDB config** based on your workload: |
| 249 | + - Read-heavy? Use `DatabaseConfig.ReadHeavy` |
| 250 | + - Write-heavy? Use `DatabaseConfig.WriteHeavy` |
| 251 | + - Low memory? Use `DatabaseConfig.LowMemory` |
| 252 | + |
| 253 | +## Questions? |
| 254 | + |
| 255 | +See: |
| 256 | +- `README.md` - Overall SharpCoreDB documentation |
| 257 | +- `docs/features/PERFORMANCE_OPTIMIZATIONS.md` - Detailed optimization guide |
| 258 | +- `docs/guides/MIGRATION_GUIDE_V1.md` - How to apply optimizations |
| 259 | + |
| 260 | +--- |
| 261 | + |
| 262 | +**Happy Benchmarking!** 🚀 |
0 commit comments