"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const benchmark_1 = require("@fluid-tools/benchmark");
const ops_js_1 = require("../ops.js");
const perspective_js_1 = require("../perspective.js");
const revertibles_js_1 = require("../revertibles.js");
const snapshot_utils_js_1 = require("./snapshot.utils.js");
describe("MergeTree remove", () => {
    let summary;
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        // baseline summary benchmark to compare to other remove tests. such a
        // comparison should give a (rough) sense of overhead caused by summary
        // loading
        title: "baseline summary load",
        category: "remove",
        before: () => {
            const str = new snapshot_utils_js_1.TestString("id", {});
            for (let i = 0; i < 1000; i++) {
                str.append("a", false);
            }
            str.applyPendingOps();
            summary = str.getSummary();
        },
        benchmarkFnAsync: async () => {
            await (0, snapshot_utils_js_1.loadSnapshot)(summary);
        },
    });
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "remove large range of large tree",
        category: "remove",
        before: () => {
            const str = new snapshot_utils_js_1.TestString("id", {});
            for (let i = 0; i < 1000; i++) {
                str.append("a", false);
            }
            str.applyPendingOps();
            summary = str.getSummary();
        },
        benchmarkFnAsync: async () => {
            const str = await (0, snapshot_utils_js_1.loadSnapshot)(summary);
            const refSeq = 1000;
            const clientId = 0;
            str.mergeTree.markRangeRemoved(0, 1000, new perspective_js_1.PriorPerspective(refSeq, clientId), { seq: 1001, clientId }, { op: { type: ops_js_1.MergeTreeDeltaType.REMOVE } });
        },
    });
    for (const length of [10, 100, 1000]) {
        (0, benchmark_1.benchmark)({
            type: benchmark_1.BenchmarkType.Measurement,
            title: "remove large range of large tree with undo-redo",
            category: "remove",
            before: () => {
                const str = new snapshot_utils_js_1.TestString("id", {});
                for (let i = 0; i < length / 2; i++) {
                    str.append("a", true);
                    str.appendMarker(true);
                }
                str.applyPendingOps();
                summary = str.getSummary();
            },
            benchmarkFnAsync: async () => {
                const str = await (0, snapshot_utils_js_1.loadSnapshot)(summary);
                const revertibles = [];
                str.on("delta", (_op, delta) => {
                    (0, revertibles_js_1.appendToMergeTreeDeltaRevertibles)(delta, revertibles);
                });
                const op = str.removeRangeLocal(0, length - 1);
                str.applyMsg(str.makeOpMessage(op, 
                /* seq */ length + 1, 
                /* refSeq */ length, str.longClientId, 
                /* minSeq */ length));
            },
        });
    }
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "remove start of large tree",
        category: "remove",
        before: () => {
            const str = new snapshot_utils_js_1.TestString("id", {});
            for (let i = 0; i < 1000; i++) {
                str.append("a", false);
            }
            str.applyPendingOps();
            summary = str.getSummary();
        },
        benchmarkFnAsync: async () => {
            const str = await (0, snapshot_utils_js_1.loadSnapshot)(summary);
            const refSeq = 1000;
            const clientId = 0;
            str.mergeTree.markRangeRemoved(0, 1, new perspective_js_1.PriorPerspective(refSeq, clientId), { seq: 1001, clientId }, { op: { type: ops_js_1.MergeTreeDeltaType.REMOVE } });
        },
    });
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "remove middle of large tree",
        category: "remove",
        before: () => {
            const str = new snapshot_utils_js_1.TestString("id", {});
            for (let i = 0; i < 1000; i++) {
                str.append("a", false);
            }
            str.applyPendingOps();
            summary = str.getSummary();
        },
        benchmarkFnAsync: async () => {
            const str = await (0, snapshot_utils_js_1.loadSnapshot)(summary);
            const refSeq = 1000;
            const clientId = 0;
            str.mergeTree.markRangeRemoved(499, 501, new perspective_js_1.PriorPerspective(refSeq, clientId), { seq: 1001, clientId }, { op: { type: ops_js_1.MergeTreeDeltaType.REMOVE } });
        },
    });
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "remove end of large tree",
        category: "remove",
        before: () => {
            const str = new snapshot_utils_js_1.TestString("id", {});
            for (let i = 0; i < 1000; i++) {
                str.append("a", false);
            }
            str.applyPendingOps();
            summary = str.getSummary();
        },
        benchmarkFnAsync: async () => {
            const str = await (0, snapshot_utils_js_1.loadSnapshot)(summary);
            const refSeq = 1000;
            const clientId = 0;
            str.mergeTree.markRangeRemoved(999, 1000, new perspective_js_1.PriorPerspective(refSeq, clientId), { seq: 1001, clientId }, { op: { type: ops_js_1.MergeTreeDeltaType.REMOVE } });
        },
    });
});
//# sourceMappingURL=Removal.perf.spec.js.map