Skip to content

Commit 13ef1e3

Browse files
committed
Merge branch 'fix-large-text-benchmark'
2 parents 190108d + 0e9523a commit 13ef1e3

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

benchmark/marker-index.benchmark.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
'use strict';
22

3+
console.log(' running marker-index tests... \n')
4+
35
const Random = require('random-seed')
6+
const {performance} = require("perf_hooks")
7+
48
const {MarkerIndex} = require('..')
59
const {traverse, traversalDistance, compare} = require('../test/js/helpers/point-helpers')
610

@@ -41,12 +45,13 @@ function runBenchmark () {
4145
}
4246

4347
function profileOperations (name, operations) {
44-
console.time(name)
48+
const ti1 = performance.now()
4549
for (let i = 0, n = operations.length; i < n; i++) {
4650
const operation = operations[i]
4751
markerIndex[operation[0]].apply(markerIndex, operation[1])
4852
}
49-
console.timeEnd(name)
53+
const tf1 = performance.now()
54+
console.log(`${name} ${' '.repeat(80-name.length)} ${(tf1-ti1).toFixed(3)} ms`)
5055
}
5156

5257
function enqueueSequentialInsert () {
@@ -118,3 +123,5 @@ function getSplice () {
118123
}
119124

120125
runBenchmark()
126+
127+
console.log(' \n marker-index finished \n')

benchmark/text-buffer.benchmark.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
console.log(' running text-buffer tests... \n')
2+
13
const assert = require('assert')
4+
const {performance} = require("perf_hooks")
5+
26
const {TextBuffer} = require('..')
37

48
const text = 'abc def ghi jkl\n'.repeat(1024 * 1024)
@@ -8,14 +12,15 @@ const trialCount = 10
812

913
function benchmarkSearch(description, pattern, expectedPosition) {
1014
let name = `Search for ${description} - TextBuffer`
11-
console.time(name)
15+
const ti1 = performance.now()
1216
for (let i = 0; i < trialCount; i++) {
13-
assert.deepEqual(buffer.searchSync(pattern), expectedPosition)
17+
assert.deepEqual(buffer.findSync(pattern), expectedPosition)
1418
}
15-
console.timeEnd(name)
19+
const tf1 = performance.now()
20+
console.log(`${name} ${' '.repeat(80-name.length)} ${(tf1-ti1).toFixed(3)} ms`)
1621

1722
name = `Search for ${description} - lines array`
18-
console.time(name)
23+
const ti2 = performance.now()
1924
const regex = new RegExp(pattern)
2025
for (let i = 0; i < trialCount; i++) {
2126
for (let row = 0, rowCount = lines.length; row < rowCount; row++) {
@@ -32,11 +37,14 @@ function benchmarkSearch(description, pattern, expectedPosition) {
3237
}
3338
}
3439
}
35-
console.timeEnd(name)
36-
console.log()
40+
const tf2 = performance.now()
41+
console.log(`${name} ${' '.repeat(80-name.length)} ${(tf2-ti2).toFixed(3)} ms`)
3742
}
3843

3944
benchmarkSearch('simple non-existent pattern', '\t', null)
4045
benchmarkSearch('complex non-existent pattern', '123|456|789', null)
4146
benchmarkSearch('simple existing pattern', 'jkl', {start: {row: 0, column: 12}, end: {row: 0, column: 15}})
42-
benchmarkSearch('complex existing pattern', 'j\\w+', {start: {row: 0, column: 12}, end: {row: 0, column: 15}})
47+
benchmarkSearch('complex existing pattern', 'j\\w+', {start: {row: 0, column: 12}, end: {row: 0, column: 15}})
48+
49+
50+
console.log('\n text-buffer finished \n')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test:node": "mocha test/js/*.js",
1313
"test:browser": "SUPERSTRING_USE_BROWSER_VERSION=1 mocha test/js/*.js",
1414
"test": "npm run test:node && npm run test:browser",
15-
"benchmark": "node benchmark/marker-index.benchmark.js && node benchmark/large-text-buffer.benchmark.js",
15+
"benchmark": "node benchmark/text-buffer.benchmark.js && node benchmark/marker-index.benchmark.js && node benchmark/large-text-buffer.benchmark.js",
1616
"prepublishOnly": "git submodule update --init --recursive && npm run build:browser",
1717
"standard": "standard --recursive src test",
1818
"format": "clang-format -i src/core/*.cc src/core/*.h src/bindings/*.cc src/bindings/*.h src/bindings/em/*.cc src/bindings/em/*.h",

0 commit comments

Comments
 (0)