From 17da325bb4ddeda07d29ade39ff969fab1599d2c Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Fri, 9 Oct 2015 14:29:15 -0700 Subject: [PATCH] Add List of Common Cases to AttributePayload Benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: The most common cases is either that nothing changed or that only one part of an array changed. @​public Reviewed By: @spicyj Differential Revision: D2516385 fb-gh-sync-id: 0cd09b95ebac37ee1b575025d23ae2f2e6e2fb47 --- .../ReactNativeAttributePayload-benchmark.js | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Libraries/ReactNative/__benchmarks__/ReactNativeAttributePayload-benchmark.js b/Libraries/ReactNative/__benchmarks__/ReactNativeAttributePayload-benchmark.js index 13dad92ae..08f387928 100644 --- a/Libraries/ReactNative/__benchmarks__/ReactNativeAttributePayload-benchmark.js +++ b/Libraries/ReactNative/__benchmarks__/ReactNativeAttributePayload-benchmark.js @@ -238,6 +238,18 @@ var variants = { l5: large5, }; +var commonCases = [ + // Reference equality + 'l1l1', + // Equal but not reference equal + 's3s4', + 'm3m4', + 'l4l5', + // Complex base style with a small change in the end + 'l3l4', + 'l4l3', +]; + // Differ var validAttributes = require('ReactNativeViewAttributes').UIView; @@ -248,6 +260,8 @@ var Differ = require('ReactNativeAttributePayload'); var numberOfBenchmarks = 0; var totalTimeForAllBenchmarks = 0; +var numberOfCommonCases = 0; +var totalTimeForAllCommonCases = 0; var results = {}; function runBenchmarkOnce(value1, value2) { @@ -256,7 +270,7 @@ function runBenchmarkOnce(value1, value2) { Differ.diff({}, value1, validAttributes); var cache = Differ.previousFlattenedStyle; var start = Date.now(); - for (var i = 0; i < 100; i++) { + for (var i = 0; i < 1000; i++) { Differ.diff(value1, value2, validAttributes); Differ.previousFlattenedStyle = cache; } @@ -265,14 +279,23 @@ function runBenchmarkOnce(value1, value2) { } function runBenchmark(key1, key2, value1, value2) { + if (results.hasOwnProperty(key1 + key2)) { + // dedupe same test that runs twice. E.g. key1 === key2 + return; + } var totalTime = 0; var nthRuns = 5; for (var i = 0; i < nthRuns; i++) { totalTime += runBenchmarkOnce(value1, value2); } - results[key1 + key2] = totalTime / nthRuns; - totalTimeForAllBenchmarks += totalTime / nthRuns; + var runTime = totalTime / nthRuns; + results[key1 + key2] = runTime; + totalTimeForAllBenchmarks += runTime; numberOfBenchmarks++; + if (commonCases.indexOf(key1 + key2) > -1) { + numberOfCommonCases++; + totalTimeForAllCommonCases += runTime; + } } function runAllCombinations() { @@ -304,6 +327,10 @@ function formatResult() { } } + str += 'Common cases: ' + + (totalTimeForAllCommonCases / numberOfCommonCases) + + ' units\n'; + str += 'Worst case: ' + worstCase + ' units\n'; str += 'Per combination:\n';