@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.
Files changed (34) hide show
  1. package/lib/commonjs/benchmarking/BenchmarkComparator.js +221 -1
  2. package/lib/commonjs/benchmarking/BenchmarkRecorder.js +497 -1
  3. package/lib/commonjs/benchmarking/BenchmarkStorage.js +235 -1
  4. package/lib/commonjs/benchmarking/index.js +83 -1
  5. package/lib/commonjs/benchmarking/types.js +13 -1
  6. package/lib/commonjs/components/BenchmarkCompareView.js +475 -1
  7. package/lib/commonjs/components/BenchmarkDetailView.js +346 -1
  8. package/lib/commonjs/components/BenchmarkModal.js +505 -1
  9. package/lib/commonjs/components/BenchmarkSessionCard.js +193 -1
  10. package/lib/commonjs/index.js +62 -1
  11. package/lib/commonjs/preset.js +86 -1
  12. package/lib/module/benchmarking/BenchmarkComparator.js +216 -1
  13. package/lib/module/benchmarking/BenchmarkRecorder.js +493 -1
  14. package/lib/module/benchmarking/BenchmarkStorage.js +227 -1
  15. package/lib/module/benchmarking/index.js +48 -1
  16. package/lib/module/benchmarking/types.js +13 -1
  17. package/lib/module/components/BenchmarkCompareView.js +469 -1
  18. package/lib/module/components/BenchmarkDetailView.js +340 -1
  19. package/lib/module/components/BenchmarkModal.js +499 -1
  20. package/lib/module/components/BenchmarkSessionCard.js +187 -1
  21. package/lib/module/index.js +39 -1
  22. package/lib/module/preset.js +81 -1
  23. package/lib/typescript/benchmarking/BenchmarkComparator.d.ts.map +1 -0
  24. package/lib/typescript/benchmarking/BenchmarkRecorder.d.ts.map +1 -0
  25. package/lib/typescript/benchmarking/BenchmarkStorage.d.ts.map +1 -0
  26. package/lib/typescript/benchmarking/index.d.ts.map +1 -0
  27. package/lib/typescript/benchmarking/types.d.ts.map +1 -0
  28. package/lib/typescript/components/BenchmarkCompareView.d.ts.map +1 -0
  29. package/lib/typescript/components/BenchmarkDetailView.d.ts.map +1 -0
  30. package/lib/typescript/components/BenchmarkModal.d.ts.map +1 -0
  31. package/lib/typescript/components/BenchmarkSessionCard.d.ts.map +1 -0
  32. package/lib/typescript/index.d.ts.map +1 -0
  33. package/lib/typescript/preset.d.ts.map +1 -0
  34. package/package.json +2 -2
@@ -1 +1,235 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BenchmarkStorage=void 0,exports.createAsyncStorageAdapter=createAsyncStorageAdapter,exports.createMemoryStorageAdapter=createMemoryStorageAdapter,exports.default=void 0;const STORAGE_PREFIX="@buoy-gg/benchmark",INDEX_KEY=`${STORAGE_PREFIX}/index`,REPORT_KEY_PREFIX=`${STORAGE_PREFIX}/report/`;function getReportKey(e){return`${REPORT_KEY_PREFIX}${e}`}function extractMetadata(e){return{id:e.id,name:e.name,description:e.description,createdAt:e.createdAt,duration:e.duration,batchCount:e.stats.batchCount}}class BenchmarkStorage{constructor(e){this.storage=e}async saveReport(e){const t=await this.loadIndex(),r=t.findIndex(t=>t.id===e.id);return r>=0?t[r]=extractMetadata(e):t.push(extractMetadata(e)),await Promise.all([this.storage.setItem(getReportKey(e.id),JSON.stringify(e)),this.storage.setItem(INDEX_KEY,JSON.stringify(t))]),extractMetadata(e)}async loadReport(e){try{const t=await this.storage.getItem(getReportKey(e));return t?JSON.parse(t):null}catch(t){return console.error(`[BenchmarkStorage] Error loading report ${e}:`,t),null}}async listReports(){return(await this.loadIndex()).sort((e,t)=>t.createdAt-e.createdAt)}async deleteReport(e){const t=await this.loadIndex(),r=t.findIndex(t=>t.id===e);return!(r<0||(t.splice(r,1),await Promise.all([this.storage.removeItem(getReportKey(e)),this.storage.setItem(INDEX_KEY,JSON.stringify(t))]),0))}async clearAll(){const e=await this.loadIndex();await Promise.all([...e.map(e=>this.storage.removeItem(getReportKey(e.id))),this.storage.removeItem(INDEX_KEY)])}async updateReport(e,t){const r=await this.loadReport(e);return!!r&&(void 0!==t.name&&(r.name=t.name),void 0!==t.description&&(r.description=t.description),await this.saveReport(r),!0)}async getMostRecent(){const e=await this.listReports();return 0===e.length?null:this.loadReport(e[0].id)}async getReportsByName(e){return(await this.loadIndex()).filter(t=>t.name===e).sort((e,t)=>t.createdAt-e.createdAt)}async loadIndex(){try{const e=await this.storage.getItem(INDEX_KEY);return e?JSON.parse(e):[]}catch(e){return console.error("[BenchmarkStorage] Error loading index:",e),[]}}}function createAsyncStorageAdapter(){try{const e=require("@react-native-async-storage/async-storage").default;return{getItem:t=>e.getItem(t),setItem:(t,r)=>e.setItem(t,r),removeItem:t=>e.removeItem(t)}}catch{return console.warn("[BenchmarkStorage] @react-native-async-storage/async-storage not available. Provide a custom storage adapter."),null}}function createMemoryStorageAdapter(){const e=new Map;return{getItem:async t=>e.get(t)??null,setItem:async(t,r)=>{e.set(t,r)},removeItem:async t=>{e.delete(t)}}}exports.BenchmarkStorage=BenchmarkStorage;var _default=exports.default=BenchmarkStorage;
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
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"BenchmarkComparator",{enumerable:!0,get:function(){return _BenchmarkComparator.BenchmarkComparator}}),Object.defineProperty(exports,"BenchmarkRecorder",{enumerable:!0,get:function(){return _BenchmarkRecorder.BenchmarkRecorder}}),Object.defineProperty(exports,"BenchmarkStorage",{enumerable:!0,get:function(){return _BenchmarkStorage.BenchmarkStorage}}),Object.defineProperty(exports,"benchmarkRecorder",{enumerable:!0,get:function(){return _BenchmarkRecorder.benchmarkRecorder}}),Object.defineProperty(exports,"createAsyncStorageAdapter",{enumerable:!0,get:function(){return _BenchmarkStorage.createAsyncStorageAdapter}}),Object.defineProperty(exports,"createMemoryStorageAdapter",{enumerable:!0,get:function(){return _BenchmarkStorage.createMemoryStorageAdapter}});var _BenchmarkRecorder=require("./BenchmarkRecorder"),_BenchmarkStorage=require("./BenchmarkStorage"),_BenchmarkComparator=require("./BenchmarkComparator");
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");
@@ -1 +1,13 @@
1
- "use strict";
1
+ /**
2
+ * Benchmarking Types
3
+ *
4
+ * Core type definitions for the performance benchmarking system.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ "use strict";
10
+
11
+ /**
12
+ * High-resolution timestamp in milliseconds
13
+ */