-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark-cache.ps1
More file actions
128 lines (115 loc) Β· 5.96 KB
/
benchmark-cache.ps1
File metadata and controls
128 lines (115 loc) Β· 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# UFFS Cache Benchmark Script
# Tests index vs dataframe modes across single drives and all-drives scenarios
# Compares against C++ baseline (uffs.com)
param(
[int]$N = 5, # Rounds per test
[switch]$ClearCache, # Clear cache before running
[switch]$SkipCpp # Skip C++ baseline tests
)
$ErrorActionPreference = "Stop"
$UFFS = "$env:USERPROFILE\bin\uffs.exe"
$UFFS_CPP = "$env:USERPROFILE\bin\uffs.com"
$CACHE_DIR = "$env:TEMP\uffs_index_cache"
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " UFFS Cache Benchmark" -ForegroundColor Cyan
Write-Host " Rounds per test: $N" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
# Clear cache if requested
if ($ClearCache) {
Write-Host "ποΈ Clearing cache at $CACHE_DIR..." -ForegroundColor Yellow
Remove-Item $CACHE_DIR -Recurse -Force -ErrorAction SilentlyContinue
Write-Host " Cache cleared.`n" -ForegroundColor Green
}
# Show cache status
if (Test-Path $CACHE_DIR) {
$cacheFiles = Get-ChildItem $CACHE_DIR -Filter "*.uffs" -ErrorAction SilentlyContinue
Write-Host "π¦ Cache status: $($cacheFiles.Count) cached drive(s)" -ForegroundColor Gray
foreach ($f in $cacheFiles) {
$age = [math]::Round(((Get-Date) - $f.LastWriteTime).TotalMinutes, 1)
Write-Host " - $($f.Name) (age: ${age}m, size: $([math]::Round($f.Length/1MB, 1))MB)" -ForegroundColor Gray
}
Write-Host ""
} else {
Write-Host "π¦ Cache status: Empty (first run will populate)`n" -ForegroundColor Gray
}
function Bench($label, $cmd) {
$times = @()
1..$N | ForEach-Object {
$sw = [System.Diagnostics.Stopwatch]::StartNew()
try {
& $cmd | Out-Null
} catch {
Write-Host " β οΈ Error: $_" -ForegroundColor Red
}
$sw.Stop()
$times += $sw.Elapsed.TotalMilliseconds
}
if ($times.Count -gt 0) {
$avg = ($times | Measure-Object -Average).Average
$min = ($times | Measure-Object -Minimum).Minimum
$max = ($times | Measure-Object -Maximum).Maximum
"{0,-25} avg={1,8:N0} ms min={2,8:N0} max={3,8:N0}" -f $label, $avg, $min, $max
} else {
"{0,-25} FAILED" -f $label
}
}
# ============================================
# WARM-UP (populates cache)
# ============================================
Write-Host "π₯ Warm-up (populating cache)..." -ForegroundColor Yellow
& $UFFS search "*.rs" --drive F 2>$null | Out-Null
& $UFFS search "*.rs" --drive S 2>$null | Out-Null
& $UFFS search "*.rs" 2>$null | Out-Null # All drives
Write-Host " Done.`n" -ForegroundColor Green
# ============================================
# SINGLE DRIVE: F
# ============================================
Write-Host "ββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor DarkGray
Write-Host "π DRIVE F: (single drive)" -ForegroundColor White
Write-Host "ββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor DarkGray
Bench "F: index" { & $UFFS search "*.rs" --drive F --query-mode=index }
Bench "F: dataframe" { & $UFFS search "*.rs" --drive F --query-mode=dataframe }
Bench "F: default" { & $UFFS search "*.rs" --drive F }
if (-not $SkipCpp -and (Test-Path $UFFS_CPP)) {
Bench "F: C++ baseline" { & $UFFS_CPP "*.rs" --drives=F }
}
Write-Host ""
# ============================================
# SINGLE DRIVE: S
# ============================================
Write-Host "ββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor DarkGray
Write-Host "π DRIVE S: (single drive)" -ForegroundColor White
Write-Host "ββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor DarkGray
Bench "S: index" { & $UFFS search "*.rs" --drive S --query-mode=index }
Bench "S: dataframe" { & $UFFS search "*.rs" --drive S --query-mode=dataframe }
Bench "S: default" { & $UFFS search "*.rs" --drive S }
if (-not $SkipCpp -and (Test-Path $UFFS_CPP)) {
Bench "S: C++ baseline" { & $UFFS_CPP "*.rs" --drives=S }
}
Write-Host ""
# ============================================
# ALL DRIVES (no --drive flag)
# ============================================
Write-Host "ββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor DarkGray
Write-Host "π ALL DRIVES: (no --drive specified)" -ForegroundColor White
Write-Host "ββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor DarkGray
Bench "ALL: index" { & $UFFS search "*.rs" --query-mode=index }
Bench "ALL: dataframe" { & $UFFS search "*.rs" --query-mode=dataframe }
Bench "ALL: default" { & $UFFS search "*.rs" }
if (-not $SkipCpp -and (Test-Path $UFFS_CPP)) {
Bench "ALL: C++ baseline" { & $UFFS_CPP "*.rs" }
}
Write-Host ""
# ============================================
# SUMMARY
# ============================================
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Benchmark Complete" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "`nNotes:" -ForegroundColor Gray
Write-Host " - 'index' mode: Fast path using MftIndex (lean, no DataFrame)" -ForegroundColor Gray
Write-Host " - 'dataframe' mode: Converts MftIndex to DataFrame" -ForegroundColor Gray
Write-Host " - 'default' mode: Auto-selects best path (currently index)" -ForegroundColor Gray
Write-Host " - First run populates cache; subsequent runs use cache" -ForegroundColor Gray
Write-Host " - Cache TTL: 10 minutes (600 seconds)" -ForegroundColor Gray
Write-Host "`nCache location: $CACHE_DIR" -ForegroundColor Gray