@buoy-gg/benchmark 2.1.3 → 2.1.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/benchmarking/BenchmarkComparator.js +221 -1
- package/lib/commonjs/benchmarking/BenchmarkRecorder.js +497 -1
- package/lib/commonjs/benchmarking/BenchmarkStorage.js +235 -1
- package/lib/commonjs/benchmarking/index.js +83 -1
- package/lib/commonjs/benchmarking/types.js +13 -1
- package/lib/commonjs/components/BenchmarkCompareView.js +475 -1
- package/lib/commonjs/components/BenchmarkDetailView.js +346 -1
- package/lib/commonjs/components/BenchmarkModal.js +505 -1
- package/lib/commonjs/components/BenchmarkSessionCard.js +193 -1
- package/lib/commonjs/index.js +62 -1
- package/lib/commonjs/preset.js +86 -1
- package/lib/module/benchmarking/BenchmarkComparator.js +216 -1
- package/lib/module/benchmarking/BenchmarkRecorder.js +493 -1
- package/lib/module/benchmarking/BenchmarkStorage.js +227 -1
- package/lib/module/benchmarking/index.js +48 -1
- package/lib/module/benchmarking/types.js +13 -1
- package/lib/module/components/BenchmarkCompareView.js +469 -1
- package/lib/module/components/BenchmarkDetailView.js +340 -1
- package/lib/module/components/BenchmarkModal.js +499 -1
- package/lib/module/components/BenchmarkSessionCard.js +187 -1
- package/lib/module/index.js +39 -1
- package/lib/module/preset.js +81 -1
- package/lib/typescript/benchmarking/BenchmarkComparator.d.ts.map +1 -0
- package/lib/typescript/benchmarking/BenchmarkRecorder.d.ts.map +1 -0
- package/lib/typescript/benchmarking/BenchmarkStorage.d.ts.map +1 -0
- package/lib/typescript/benchmarking/index.d.ts.map +1 -0
- package/lib/typescript/benchmarking/types.d.ts.map +1 -0
- package/lib/typescript/components/BenchmarkCompareView.d.ts.map +1 -0
- package/lib/typescript/components/BenchmarkDetailView.d.ts.map +1 -0
- package/lib/typescript/components/BenchmarkModal.d.ts.map +1 -0
- package/lib/typescript/components/BenchmarkSessionCard.d.ts.map +1 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/preset.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1,235 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* BenchmarkStorage
|
|
3
|
+
*
|
|
4
|
+
* Handles persistence of benchmark reports to AsyncStorage.
|
|
5
|
+
* Provides methods to save, load, list, and delete benchmark reports.
|
|
6
|
+
*
|
|
7
|
+
* Storage keys:
|
|
8
|
+
* - @benchmark/index: Array of report metadata (id, name, createdAt)
|
|
9
|
+
* - @benchmark/report/{id}: Full report data
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
exports.BenchmarkStorage = void 0;
|
|
20
|
+
exports.createAsyncStorageAdapter = createAsyncStorageAdapter;
|
|
21
|
+
exports.createMemoryStorageAdapter = createMemoryStorageAdapter;
|
|
22
|
+
exports.default = void 0;
|
|
23
|
+
/**
|
|
24
|
+
* Storage adapter interface - allows for different storage backends
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Metadata for a stored benchmark (stored in index)
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// Storage key prefix
|
|
32
|
+
const STORAGE_PREFIX = "@buoy-gg/benchmark";
|
|
33
|
+
const INDEX_KEY = `${STORAGE_PREFIX}/index`;
|
|
34
|
+
const REPORT_KEY_PREFIX = `${STORAGE_PREFIX}/report/`;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get the storage key for a report
|
|
38
|
+
*/
|
|
39
|
+
function getReportKey(id) {
|
|
40
|
+
return `${REPORT_KEY_PREFIX}${id}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Extract metadata from a full report
|
|
45
|
+
*/
|
|
46
|
+
function extractMetadata(report) {
|
|
47
|
+
return {
|
|
48
|
+
id: report.id,
|
|
49
|
+
name: report.name,
|
|
50
|
+
description: report.description,
|
|
51
|
+
createdAt: report.createdAt,
|
|
52
|
+
duration: report.duration,
|
|
53
|
+
batchCount: report.stats.batchCount
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* BenchmarkStorage - Manages persistence of benchmark reports
|
|
59
|
+
*/
|
|
60
|
+
class BenchmarkStorage {
|
|
61
|
+
/**
|
|
62
|
+
* Create a new BenchmarkStorage instance
|
|
63
|
+
* @param storage - Storage adapter (e.g., AsyncStorage)
|
|
64
|
+
*/
|
|
65
|
+
constructor(storage) {
|
|
66
|
+
this.storage = storage;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Save a benchmark report
|
|
71
|
+
* @returns The saved report's metadata
|
|
72
|
+
*/
|
|
73
|
+
async saveReport(report) {
|
|
74
|
+
// Load current index
|
|
75
|
+
const index = await this.loadIndex();
|
|
76
|
+
|
|
77
|
+
// Check if report already exists
|
|
78
|
+
const existingIndex = index.findIndex(m => m.id === report.id);
|
|
79
|
+
if (existingIndex >= 0) {
|
|
80
|
+
// Update existing entry
|
|
81
|
+
index[existingIndex] = extractMetadata(report);
|
|
82
|
+
} else {
|
|
83
|
+
// Add new entry
|
|
84
|
+
index.push(extractMetadata(report));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Save report and update index
|
|
88
|
+
await Promise.all([this.storage.setItem(getReportKey(report.id), JSON.stringify(report)), this.storage.setItem(INDEX_KEY, JSON.stringify(index))]);
|
|
89
|
+
return extractMetadata(report);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Load a benchmark report by ID
|
|
94
|
+
* @returns The report, or null if not found
|
|
95
|
+
*/
|
|
96
|
+
async loadReport(id) {
|
|
97
|
+
try {
|
|
98
|
+
const data = await this.storage.getItem(getReportKey(id));
|
|
99
|
+
if (!data) return null;
|
|
100
|
+
const report = JSON.parse(data);
|
|
101
|
+
return report;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error(`[BenchmarkStorage] Error loading report ${id}:`, error);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Load all benchmark metadata (for listing)
|
|
110
|
+
*/
|
|
111
|
+
async listReports() {
|
|
112
|
+
const index = await this.loadIndex();
|
|
113
|
+
// Sort by createdAt descending (newest first)
|
|
114
|
+
return index.sort((a, b) => b.createdAt - a.createdAt);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Delete a benchmark report
|
|
119
|
+
* @returns true if deleted, false if not found
|
|
120
|
+
*/
|
|
121
|
+
async deleteReport(id) {
|
|
122
|
+
// Load current index
|
|
123
|
+
const index = await this.loadIndex();
|
|
124
|
+
|
|
125
|
+
// Find and remove from index
|
|
126
|
+
const existingIndex = index.findIndex(m => m.id === id);
|
|
127
|
+
if (existingIndex < 0) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
index.splice(existingIndex, 1);
|
|
131
|
+
|
|
132
|
+
// Remove report and update index
|
|
133
|
+
await Promise.all([this.storage.removeItem(getReportKey(id)), this.storage.setItem(INDEX_KEY, JSON.stringify(index))]);
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Delete all benchmark reports
|
|
139
|
+
*/
|
|
140
|
+
async clearAll() {
|
|
141
|
+
const index = await this.loadIndex();
|
|
142
|
+
|
|
143
|
+
// Delete all reports
|
|
144
|
+
await Promise.all([...index.map(m => this.storage.removeItem(getReportKey(m.id))), this.storage.removeItem(INDEX_KEY)]);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Update a benchmark report's name and/or description
|
|
149
|
+
* @returns true if updated, false if not found
|
|
150
|
+
*/
|
|
151
|
+
async updateReport(id, updates) {
|
|
152
|
+
// Load the report
|
|
153
|
+
const report = await this.loadReport(id);
|
|
154
|
+
if (!report) return false;
|
|
155
|
+
|
|
156
|
+
// Apply updates
|
|
157
|
+
if (updates.name !== undefined) {
|
|
158
|
+
report.name = updates.name;
|
|
159
|
+
}
|
|
160
|
+
if (updates.description !== undefined) {
|
|
161
|
+
report.description = updates.description;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Save updated report (this also updates the index)
|
|
165
|
+
await this.saveReport(report);
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get the most recent report
|
|
171
|
+
*/
|
|
172
|
+
async getMostRecent() {
|
|
173
|
+
const reports = await this.listReports();
|
|
174
|
+
if (reports.length === 0) return null;
|
|
175
|
+
return this.loadReport(reports[0].id);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get reports by name (for comparing multiple runs of same benchmark)
|
|
180
|
+
*/
|
|
181
|
+
async getReportsByName(name) {
|
|
182
|
+
const index = await this.loadIndex();
|
|
183
|
+
return index.filter(m => m.name === name).sort((a, b) => b.createdAt - a.createdAt);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Load the index of all benchmarks
|
|
188
|
+
*/
|
|
189
|
+
async loadIndex() {
|
|
190
|
+
try {
|
|
191
|
+
const data = await this.storage.getItem(INDEX_KEY);
|
|
192
|
+
if (!data) return [];
|
|
193
|
+
return JSON.parse(data);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error("[BenchmarkStorage] Error loading index:", error);
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Create a storage instance using AsyncStorage
|
|
203
|
+
*/
|
|
204
|
+
exports.BenchmarkStorage = BenchmarkStorage;
|
|
205
|
+
function createAsyncStorageAdapter() {
|
|
206
|
+
try {
|
|
207
|
+
// Dynamic import to avoid hard dependency on AsyncStorage
|
|
208
|
+
const AsyncStorage = require("@react-native-async-storage/async-storage").default;
|
|
209
|
+
return {
|
|
210
|
+
getItem: key => AsyncStorage.getItem(key),
|
|
211
|
+
setItem: (key, value) => AsyncStorage.setItem(key, value),
|
|
212
|
+
removeItem: key => AsyncStorage.removeItem(key)
|
|
213
|
+
};
|
|
214
|
+
} catch {
|
|
215
|
+
console.warn("[BenchmarkStorage] @react-native-async-storage/async-storage not available. " + "Provide a custom storage adapter.");
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* In-memory storage adapter (for testing or when AsyncStorage is not available)
|
|
222
|
+
*/
|
|
223
|
+
function createMemoryStorageAdapter() {
|
|
224
|
+
const store = new Map();
|
|
225
|
+
return {
|
|
226
|
+
getItem: async key => store.get(key) ?? null,
|
|
227
|
+
setItem: async (key, value) => {
|
|
228
|
+
store.set(key, value);
|
|
229
|
+
},
|
|
230
|
+
removeItem: async key => {
|
|
231
|
+
store.delete(key);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
var _default = exports.default = BenchmarkStorage;
|
|
@@ -1 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @buoy-gg/benchmark/benchmarking
|
|
3
|
+
*
|
|
4
|
+
* Performance benchmarking system for measuring and comparing
|
|
5
|
+
* highlight updates performance. Uses the W3C Performance API
|
|
6
|
+
* for accurate timing measurements.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {
|
|
11
|
+
* benchmarkRecorder,
|
|
12
|
+
* BenchmarkStorage,
|
|
13
|
+
* BenchmarkComparator,
|
|
14
|
+
* createAsyncStorageAdapter,
|
|
15
|
+
* } from '@buoy-gg/benchmark';
|
|
16
|
+
*
|
|
17
|
+
* // Start recording
|
|
18
|
+
* benchmarkRecorder.startSession({ name: 'MyBenchmark' });
|
|
19
|
+
*
|
|
20
|
+
* // ... perform operations ...
|
|
21
|
+
*
|
|
22
|
+
* // Stop and get report
|
|
23
|
+
* const report = benchmarkRecorder.stopSession();
|
|
24
|
+
*
|
|
25
|
+
* // Save report
|
|
26
|
+
* const storage = new BenchmarkStorage(createAsyncStorageAdapter()!);
|
|
27
|
+
* await storage.saveReport(report);
|
|
28
|
+
*
|
|
29
|
+
* // Compare with previous
|
|
30
|
+
* const previous = await storage.getMostRecent();
|
|
31
|
+
* if (previous) {
|
|
32
|
+
* BenchmarkComparator.quickCompare(previous, report);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @packageDocumentation
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
"use strict";
|
|
40
|
+
|
|
41
|
+
// Types
|
|
42
|
+
Object.defineProperty(exports, "__esModule", {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "BenchmarkComparator", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () {
|
|
48
|
+
return _BenchmarkComparator.BenchmarkComparator;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "BenchmarkRecorder", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _BenchmarkRecorder.BenchmarkRecorder;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "BenchmarkStorage", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () {
|
|
60
|
+
return _BenchmarkStorage.BenchmarkStorage;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "benchmarkRecorder", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () {
|
|
66
|
+
return _BenchmarkRecorder.benchmarkRecorder;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "createAsyncStorageAdapter", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () {
|
|
72
|
+
return _BenchmarkStorage.createAsyncStorageAdapter;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "createMemoryStorageAdapter", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return _BenchmarkStorage.createMemoryStorageAdapter;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
var _BenchmarkRecorder = require("./BenchmarkRecorder");
|
|
82
|
+
var _BenchmarkStorage = require("./BenchmarkStorage");
|
|
83
|
+
var _BenchmarkComparator = require("./BenchmarkComparator");
|