@@ -238,6 +238,18 @@ var variants = {
238238 l5 : large5 ,
239239} ;
240240
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+
241253// Differ
242254
243255var validAttributes = require ( 'ReactNativeViewAttributes' ) . UIView ;
@@ -248,6 +260,8 @@ var Differ = require('ReactNativeAttributePayload');
248260
249261var numberOfBenchmarks = 0 ;
250262var totalTimeForAllBenchmarks = 0 ;
263+ var numberOfCommonCases = 0 ;
264+ var totalTimeForAllCommonCases = 0 ;
251265var results = { } ;
252266
253267function runBenchmarkOnce ( value1 , value2 ) {
@@ -256,7 +270,7 @@ function runBenchmarkOnce(value1, value2) {
256270 Differ . diff ( { } , value1 , validAttributes ) ;
257271 var cache = Differ . previousFlattenedStyle ;
258272 var start = Date . now ( ) ;
259- for ( var i = 0 ; i < 100 ; i ++ ) {
273+ for ( var i = 0 ; i < 1000 ; i ++ ) {
260274 Differ . diff ( value1 , value2 , validAttributes ) ;
261275 Differ . previousFlattenedStyle = cache ;
262276 }
@@ -265,14 +279,23 @@ function runBenchmarkOnce(value1, value2) {
265279}
266280
267281function 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+ }
268286 var totalTime = 0 ;
269287 var nthRuns = 5 ;
270288 for ( var i = 0 ; i < nthRuns ; i ++ ) {
271289 totalTime += runBenchmarkOnce ( value1 , value2 ) ;
272290 }
273- results [ key1 + key2 ] = totalTime / nthRuns ;
274- totalTimeForAllBenchmarks += totalTime / nthRuns ;
291+ var runTime = totalTime / nthRuns ;
292+ results [ key1 + key2 ] = runTime ;
293+ totalTimeForAllBenchmarks += runTime ;
275294 numberOfBenchmarks ++ ;
295+ if ( commonCases . indexOf ( key1 + key2 ) > - 1 ) {
296+ numberOfCommonCases ++ ;
297+ totalTimeForAllCommonCases += runTime ;
298+ }
276299}
277300
278301function runAllCombinations ( ) {
@@ -304,6 +327,10 @@ function formatResult() {
304327 }
305328 }
306329
330+ str += 'Common cases: ' +
331+ ( totalTimeForAllCommonCases / numberOfCommonCases ) +
332+ ' units\n' ;
333+
307334 str += 'Worst case: ' + worstCase + ' units\n' ;
308335
309336 str += 'Per combination:\n' ;
0 commit comments