"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 mergeTree_js_1 = require("../mergeTree.js");
const ops_js_1 = require("../ops.js");
const testUtils_js_1 = require("./testUtils.js");
function constructTree(numOfSegments) {
    const mergeTree = new mergeTree_js_1.MergeTree();
    for (let i = 0; i < numOfSegments; i++) {
        (0, testUtils_js_1.insertText)({
            mergeTree,
            pos: 0,
            refSeq: i,
            clientId: 0,
            seq: i,
            text: "a",
            props: undefined,
            opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
        });
    }
    return mergeTree;
}
const TREE_SIZE = 7500;
describe("MergeTree insertion", () => {
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "insert into empty tree",
        benchmarkFn: () => {
            const emptyTree = new mergeTree_js_1.MergeTree();
            (0, testUtils_js_1.insertText)({
                mergeTree: emptyTree,
                pos: 0,
                refSeq: 0,
                clientId: 0,
                seq: 0,
                text: "a",
                props: undefined,
                opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
            });
        },
    });
    let startTree = constructTree(TREE_SIZE);
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "insert at start of large tree",
        benchmarkFn: () => {
            for (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {
                (0, testUtils_js_1.insertText)({
                    mergeTree: startTree,
                    pos: 0,
                    refSeq: i,
                    clientId: 0,
                    seq: i + 1,
                    text: "a",
                    props: undefined,
                    opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
                });
            }
        },
        beforeEachBatch: () => {
            startTree = constructTree(TREE_SIZE);
        },
    });
    let middleTree = constructTree(TREE_SIZE);
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "insert at middle of large tree",
        benchmarkFn: () => {
            for (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {
                (0, testUtils_js_1.insertText)({
                    mergeTree: middleTree,
                    pos: TREE_SIZE / 2,
                    refSeq: i,
                    clientId: 0,
                    seq: i + 1,
                    text: "a",
                    props: undefined,
                    opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
                });
            }
        },
        beforeEachBatch: () => {
            middleTree = constructTree(TREE_SIZE);
        },
    });
    let endTree = constructTree(TREE_SIZE);
    (0, benchmark_1.benchmark)({
        type: benchmark_1.BenchmarkType.Measurement,
        title: "insert at end of large tree",
        benchmarkFn: () => {
            for (let i = TREE_SIZE; i < TREE_SIZE + 25; i++) {
                (0, testUtils_js_1.insertText)({
                    mergeTree: endTree,
                    pos: i,
                    refSeq: i,
                    clientId: 0,
                    seq: i + 1,
                    text: "a",
                    props: undefined,
                    opArgs: { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } },
                });
            }
        },
        beforeEachBatch: () => {
            endTree = constructTree(TREE_SIZE);
        },
    });
});
//# sourceMappingURL=Insertion.perf.spec.js.map