Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17da325

Browse files
sebmarkbagefacebook-github-bot-4
authored and
facebook-github-bot-4
committed
Add List of Common Cases to AttributePayload Benchmark
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
1 parent 5369ccd commit 17da325

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

Libraries/ReactNative/__benchmarks__/ReactNativeAttributePayload-benchmark.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

243255
var validAttributes = require('ReactNativeViewAttributes').UIView;
@@ -248,6 +260,8 @@ var Differ = require('ReactNativeAttributePayload');
248260

249261
var numberOfBenchmarks = 0;
250262
var totalTimeForAllBenchmarks = 0;
263+
var numberOfCommonCases = 0;
264+
var totalTimeForAllCommonCases = 0;
251265
var results = {};
252266

253267
function 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

267281
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+
}
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

278301
function 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

Comments
 (0)