1
1
import { create } from "zustand" ;
2
2
import { jStat } from "jstat" ;
3
- import { frameworks , benchmarks as rawBenchmarks , results as rawResults } from "./results" ;
3
+ import { frameworks as rawFrameworks , benchmarks as rawBenchmarks , results as rawResults } from "./results" ;
4
4
import {
5
5
Benchmark ,
6
6
BenchmarkType ,
@@ -16,7 +16,21 @@ import {
16
16
knownIssues ,
17
17
} from "@/Common" ;
18
18
19
- const benchmarks = rawBenchmarks ;
19
+ const removeKeyedSuffix = ( value : string ) => {
20
+ return value . replace ( / - k e y e d | - n o n - k e y e d $ / , "" ) ;
21
+ } ;
22
+
23
+ const mappedFrameworks = rawFrameworks . map ( ( f ) => ( {
24
+ name : f . name ,
25
+ dir : f . dir ,
26
+ displayname : removeKeyedSuffix ( f . name ) ,
27
+ issues : f . issues ?? [ ] ,
28
+ type : f . keyed ? FrameworkType . KEYED : FrameworkType . NON_KEYED ,
29
+ frameworkHomeURL : f . frameworkHomeURL ,
30
+ } ) ) ;
31
+
32
+ const allBenchmarks = new Set ( rawBenchmarks ) ;
33
+ const allFrameworks = new Set ( mappedFrameworks ) ;
20
34
21
35
const results : Result [ ] = [ ] ;
22
36
for ( let result of rawResults ) {
@@ -32,28 +46,10 @@ for (let result of rawResults) {
32
46
} ;
33
47
values [ key ] = vals ;
34
48
}
35
- results . push ( { framework : frameworks [ result . f ] . name , benchmark : benchmarks [ b . b ] . id , results : values } ) ;
49
+ results . push ( { framework : rawFrameworks [ result . f ] . name , benchmark : rawBenchmarks [ b . b ] . id , results : values } ) ;
36
50
}
37
51
}
38
- console . log ( results )
39
-
40
- const removeKeyedSuffix = ( value : string ) => {
41
- if ( value . endsWith ( "-non-keyed" ) ) return value . slice ( 0 , - 10 ) ;
42
- else if ( value . endsWith ( "-keyed" ) ) return value . slice ( 0 , - 6 ) ;
43
- return value ;
44
- } ;
45
-
46
- const mappedFrameworks = frameworks . map ( ( f ) => ( {
47
- name : f . name ,
48
- dir : f . dir ,
49
- displayname : removeKeyedSuffix ( f . name ) ,
50
- issues : f . issues ?? [ ] ,
51
- type : f . keyed ? FrameworkType . KEYED : FrameworkType . NON_KEYED ,
52
- frameworkHomeURL : f . frameworkHomeURL ,
53
- } ) ) ;
54
-
55
- const allBenchmarks = new Set ( benchmarks ) ;
56
- const allFrameworks = new Set ( mappedFrameworks ) ;
52
+ console . log ( results ) ;
57
53
58
54
const resultLookup = convertToMap ( results ) ;
59
55
@@ -145,40 +141,49 @@ function updateResultTable({
145
141
} ;
146
142
}
147
143
148
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
149
- function extractState ( state : any ) : Partial < State > {
150
- let t = { } ;
151
- if ( state . benchmarks !== undefined ) {
144
+ interface ClipboardState {
145
+ benchmarks : string [ ] ;
146
+ frameworks : string [ ] ;
147
+ displayMode : DisplayMode ;
148
+ }
149
+
150
+ function extractClipboardState ( state : ClipboardState ) : Partial < State > {
151
+ const newState : Partial < State > = { } ;
152
+
153
+ if ( state . benchmarks ) {
152
154
const newSelectedBenchmarks = new Set < Benchmark > ( ) ;
153
- for ( const b of state . benchmarks ) {
154
- for ( const sb of benchmarks ) {
155
- if ( b === sb . id ) newSelectedBenchmarks . add ( sb ) ;
155
+ for ( const benchmark of state . benchmarks ) {
156
+ for ( const sb of rawBenchmarks ) {
157
+ if ( benchmark === sb . id ) newSelectedBenchmarks . add ( sb ) ;
156
158
}
157
159
}
158
- t = { ... t , selectedBenchmarks : newSelectedBenchmarks } ;
160
+ newState . selectedBenchmarks = newSelectedBenchmarks ;
159
161
}
160
- if ( state . frameworks !== undefined ) {
162
+
163
+ if ( state . frameworks ) {
161
164
const newSelectedFramework = new Set < Framework > ( ) ;
162
- for ( const f of state . frameworks ) {
165
+ for ( const framework of state . frameworks ) {
163
166
for ( const sf of mappedFrameworks ) {
164
- if ( f === sf . dir ) newSelectedFramework . add ( sf ) ;
167
+ if ( framework === sf . dir ) newSelectedFramework . add ( sf ) ;
165
168
}
166
169
}
167
- t = { ... t , selectedFrameworks : newSelectedFramework } ;
170
+ newState . selectedFrameworks = newSelectedFramework ;
168
171
}
169
- if ( state . displayMode !== undefined ) {
170
- t = { ...t , displayMode : state . displayMode } ;
172
+
173
+ if ( state . displayMode ) {
174
+ newState . displayMode = state . displayMode ;
171
175
}
172
- return t ;
176
+
177
+ return newState ;
173
178
}
174
179
175
180
const preInitialState : State = {
176
181
// State
177
- benchmarks : benchmarks ,
182
+ benchmarks : rawBenchmarks ,
178
183
benchmarkLists : {
179
- [ BenchmarkType . CPU ] : benchmarks . filter ( ( b ) => b . type === BenchmarkType . CPU ) ,
180
- [ BenchmarkType . MEM ] : benchmarks . filter ( ( b ) => b . type === BenchmarkType . MEM ) ,
181
- [ BenchmarkType . STARTUP ] : benchmarks . filter ( ( b ) => b . type === BenchmarkType . STARTUP ) ,
184
+ [ BenchmarkType . CPU ] : rawBenchmarks . filter ( ( b ) => b . type === BenchmarkType . CPU ) ,
185
+ [ BenchmarkType . MEM ] : rawBenchmarks . filter ( ( b ) => b . type === BenchmarkType . MEM ) ,
186
+ [ BenchmarkType . STARTUP ] : rawBenchmarks . filter ( ( b ) => b . type === BenchmarkType . STARTUP ) ,
182
187
} ,
183
188
frameworks : mappedFrameworks ,
184
189
frameworkLists : {
@@ -313,7 +318,7 @@ export const useRootStore = create<State & Actions>((set, get) => ({
313
318
copyStateToClipboard : ( ) => {
314
319
const currentState = get ( ) ;
315
320
316
- const serializedState = {
321
+ const serializedState : ClipboardState = {
317
322
frameworks : currentState . frameworks . filter ( ( f ) => currentState . selectedFrameworks . has ( f ) ) . map ( ( f ) => f . dir ) ,
318
323
benchmarks : currentState . benchmarks . filter ( ( f ) => currentState . selectedBenchmarks . has ( f ) ) . map ( ( f ) => f . id ) ,
319
324
displayMode : currentState . displayMode ,
@@ -334,7 +339,12 @@ export const useRootStore = create<State & Actions>((set, get) => ({
334
339
return ;
335
340
}
336
341
337
- const t = { ...get ( ) , ...extractState ( arg ) } ;
342
+ console . log ( arg ) ;
343
+
344
+ performance . mark ( "m1" ) ;
345
+ const t = { ...get ( ) , ...extractClipboardState ( arg as ClipboardState ) } ;
346
+ performance . mark ( "m2" ) ;
347
+ console . log ( performance . measure ( "State extraction" , "m1" , "m2" ) ) ;
338
348
return set ( ( ) => ( { ...t , resultTables : updateResultTable ( t ) } ) ) ;
339
349
} ,
340
350
} ) ) ;
0 commit comments