"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 textSegment_js_1 = require("../textSegment.js");
function constructTree(numOfSegments) {
    const mergeTree = new mergeTree_js_1.MergeTree();
    for (let i = 0; i < numOfSegments; i++) {
        mergeTree.insertSegments(0, [textSegment_js_1.TextSegment.make("a")], mergeTree.localPerspective, { seq: i, clientId: 0 }, { 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();
            emptyTree.insertSegments(0, [textSegment_js_1.TextSegment.make("a")], emptyTree.localPerspective, { seq: 0, clientId: 0 }, { 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++) {
                startTree.insertSegments(0, [textSegment_js_1.TextSegment.make("a")], startTree.localPerspective, { seq: i + 1, clientId: 0 }, { 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++) {
                middleTree.insertSegments(TREE_SIZE / 2, [textSegment_js_1.TextSegment.make("a")], middleTree.localPerspective, { seq: i + 1, clientId: 0 }, { 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++) {
                endTree.insertSegments(i, [textSegment_js_1.TextSegment.make("a")], endTree.localPerspective, { seq: i + 1, clientId: 0 }, { op: { type: ops_js_1.MergeTreeDeltaType.INSERT } });
            }
        },
        beforeEachBatch: () => {
            endTree = constructTree(TREE_SIZE);
        },
    });
});
//# sourceMappingURL=Insertion.perf.spec.js.map