searchNReplace.benchmark.ts 1.6 KB
Newer Older
P
Peng Lyu 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

P
Peng Lyu 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import { ITextBufferBuilder } from 'vs/editor/common/model';
import { generateRandomReplaces, generateRandomChunkWithLF } from 'vs/editor/test/common/model/linesTextBuffer/textBufferAutoTestUtils';
import { BenchmarkSuite } from 'vs/editor/test/common/model/benchmark/benchmarkUtils';

let fileSizes = [1, 1000, 64 * 1000, 32 * 1000 * 1000];

for (let fileSize of fileSizes) {
	let chunks = [];

	let chunkCnt = Math.floor(fileSize / (64 * 1000));
	if (chunkCnt === 0) {
		chunks.push(generateRandomChunkWithLF(fileSize, fileSize));
	} else {
		let chunk = generateRandomChunkWithLF(64 * 1000, 64 * 1000);
		// try to avoid OOM
		for (let j = 0; j < chunkCnt; j++) {
			chunks.push(Buffer.from(chunk + j).toString());
		}
	}

	let replaceSuite = new BenchmarkSuite({
		name: `File Size: ${fileSize}Byte`,
P
Peng Lyu 已提交
29
	});
P
Peng Lyu 已提交
30

P
Peng Lyu 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
	let edits = generateRandomReplaces(chunks, 500, 5, 10);

	for (let i of [10, 100, 500]) {
		replaceSuite.add({
			name: `replace ${i} occurrences`,
			buildBuffer: (textBufferBuilder: ITextBufferBuilder) => {
				chunks.forEach(ck => textBufferBuilder.acceptChunk(ck));
				return textBufferBuilder.finish();
			},
			preCycle: (textBuffer) => {
				return textBuffer;
			},
			fn: (textBuffer) => {
				textBuffer.applyEdits(edits.slice(0, i), false);
			}
		});
	}
P
Peng Lyu 已提交
48

P
Peng Lyu 已提交
49
	replaceSuite.run();
50
}