@@ -238,6 +238,18 @@ var variants = {
238
238
l5 : large5 ,
239
239
} ;
240
240
241
+ var commonCases = [
242
+ // Reference equality
243
+ 'l1l1' ,
244
+ // Equal but not reference equal
245
+ 's3s4' ,
246
+ 'm3m4' ,
247
+ 'l4l5' ,
248
+ // Complex base style with a small change in the end
249
+ 'l3l4' ,
250
+ 'l4l3' ,
251
+ ] ;
252
+
241
253
// Differ
242
254
243
255
var validAttributes = require ( 'ReactNativeViewAttributes' ) . UIView ;
@@ -248,6 +260,8 @@ var Differ = require('ReactNativeAttributePayload');
248
260
249
261
var numberOfBenchmarks = 0 ;
250
262
var totalTimeForAllBenchmarks = 0 ;
263
+ var numberOfCommonCases = 0 ;
264
+ var totalTimeForAllCommonCases = 0 ;
251
265
var results = { } ;
252
266
253
267
function runBenchmarkOnce ( value1 , value2 ) {
@@ -256,7 +270,7 @@ function runBenchmarkOnce(value1, value2) {
256
270
Differ . diff ( { } , value1 , validAttributes ) ;
257
271
var cache = Differ . previousFlattenedStyle ;
258
272
var start = Date . now ( ) ;
259
- for ( var i = 0 ; i < 100 ; i ++ ) {
273
+ for ( var i = 0 ; i < 1000 ; i ++ ) {
260
274
Differ . diff ( value1 , value2 , validAttributes ) ;
261
275
Differ . previousFlattenedStyle = cache ;
262
276
}
@@ -265,14 +279,23 @@ function runBenchmarkOnce(value1, value2) {
265
279
}
266
280
267
281
function runBenchmark ( key1 , key2 , value1 , value2 ) {
282
+ if ( results . hasOwnProperty ( key1 + key2 ) ) {
283
+ // dedupe same test that runs twice. E.g. key1 === key2
284
+ return ;
285
+ }
268
286
var totalTime = 0 ;
269
287
var nthRuns = 5 ;
270
288
for ( var i = 0 ; i < nthRuns ; i ++ ) {
271
289
totalTime += runBenchmarkOnce ( value1 , value2 ) ;
272
290
}
273
- results [ key1 + key2 ] = totalTime / nthRuns ;
274
- totalTimeForAllBenchmarks += totalTime / nthRuns ;
291
+ var runTime = totalTime / nthRuns ;
292
+ results [ key1 + key2 ] = runTime ;
293
+ totalTimeForAllBenchmarks += runTime ;
275
294
numberOfBenchmarks ++ ;
295
+ if ( commonCases . indexOf ( key1 + key2 ) > - 1 ) {
296
+ numberOfCommonCases ++ ;
297
+ totalTimeForAllCommonCases += runTime ;
298
+ }
276
299
}
277
300
278
301
function runAllCombinations ( ) {
@@ -304,6 +327,10 @@ function formatResult() {
304
327
}
305
328
}
306
329
330
+ str += 'Common cases: ' +
331
+ ( totalTimeForAllCommonCases / numberOfCommonCases ) +
332
+ ' units\n' ;
333
+
307
334
str += 'Worst case: ' + worstCase + ' units\n' ;
308
335
309
336
str += 'Per combination:\n' ;
0 commit comments