From 04cff60931f331cda287cba0c0fc077be1ca49e5 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Mon, 8 Feb 2021 13:46:22 +0100 Subject: [PATCH] add performance test for updates --- tests/y-text.tests.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index ad4fbc5d..dbb61457 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -368,6 +368,42 @@ export const testLargeFragmentedDocument = tc => { })() } +/** + * @param {t.TestCase} tc + */ +export const testIncrementalUpdatesPerformanceOnLargeFragmentedDocument = tc => { + const itemsToInsert = largeDocumentSize + const updates = /** @type {Array} */ ([]) + ;(() => { + const doc1 = new Y.Doc() + doc1.on('update', update => { + updates.push(update) + }) + const text0 = doc1.getText('txt') + tryGc() + t.measureTime(`time to insert ${itemsToInsert} items`, () => { + doc1.transact(() => { + for (let i = 0; i < itemsToInsert; i++) { + text0.insert(0, '0') + } + }) + }) + tryGc() + })() + ;(() => { + t.measureTime(`time to merge ${itemsToInsert} updates (differential updates)`, () => { + Y.mergeUpdates(updates) + }) + tryGc() + t.measureTime(`time to merge ${itemsToInsert} updates (ydoc updates)`, () => { + const ydoc = new Y.Doc() + updates.forEach(update => { + Y.applyUpdate(ydoc, update) + }) + }) + })() +} + /** * Splitting surrogates can lead to invalid encoded documents. *