forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat all JS files using prettier
- Loading branch information
Showing
297 changed files
with
58,685 additions
and
46,917 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,75 @@ | ||
const Chart = require('chart.js') | ||
const glob = require('glob') | ||
const fs = require('fs-plus') | ||
const path = require('path') | ||
const Chart = require('chart.js'); | ||
const glob = require('glob'); | ||
const fs = require('fs-plus'); | ||
const path = require('path'); | ||
|
||
module.exports = async ({test, benchmarkPaths}) => { | ||
document.body.style.backgroundColor = '#ffffff' | ||
document.body.style.overflow = 'auto' | ||
module.exports = async ({ test, benchmarkPaths }) => { | ||
document.body.style.backgroundColor = '#ffffff'; | ||
document.body.style.overflow = 'auto'; | ||
|
||
let paths = [] | ||
let paths = []; | ||
for (const benchmarkPath of benchmarkPaths) { | ||
if (fs.isDirectorySync(benchmarkPath)) { | ||
paths = paths.concat(glob.sync(path.join(benchmarkPath, '**', '*.bench.js'))) | ||
paths = paths.concat( | ||
glob.sync(path.join(benchmarkPath, '**', '*.bench.js')) | ||
); | ||
} else { | ||
paths.push(benchmarkPath) | ||
paths.push(benchmarkPath); | ||
} | ||
} | ||
|
||
while (paths.length > 0) { | ||
const benchmark = require(paths.shift())({test}) | ||
let results | ||
const benchmark = require(paths.shift())({ test }); | ||
let results; | ||
if (benchmark instanceof Promise) { | ||
results = await benchmark | ||
results = await benchmark; | ||
} else { | ||
results = benchmark | ||
results = benchmark; | ||
} | ||
|
||
const dataByBenchmarkName = {} | ||
for (const {name, duration, x} of results) { | ||
dataByBenchmarkName[name] = dataByBenchmarkName[name] || {points: []} | ||
dataByBenchmarkName[name].points.push({x, y: duration}) | ||
const dataByBenchmarkName = {}; | ||
for (const { name, duration, x } of results) { | ||
dataByBenchmarkName[name] = dataByBenchmarkName[name] || { points: [] }; | ||
dataByBenchmarkName[name].points.push({ x, y: duration }); | ||
} | ||
|
||
const benchmarkContainer = document.createElement('div') | ||
document.body.appendChild(benchmarkContainer) | ||
const benchmarkContainer = document.createElement('div'); | ||
document.body.appendChild(benchmarkContainer); | ||
for (const key in dataByBenchmarkName) { | ||
const data = dataByBenchmarkName[key] | ||
const data = dataByBenchmarkName[key]; | ||
if (data.points.length > 1) { | ||
const canvas = document.createElement('canvas') | ||
benchmarkContainer.appendChild(canvas) | ||
const canvas = document.createElement('canvas'); | ||
benchmarkContainer.appendChild(canvas); | ||
// eslint-disable-next-line no-new | ||
new Chart(canvas, { | ||
type: 'line', | ||
data: { | ||
datasets: [{label: key, fill: false, data: data.points}] | ||
datasets: [{ label: key, fill: false, data: data.points }] | ||
}, | ||
options: { | ||
showLines: false, | ||
scales: {xAxes: [{type: 'linear', position: 'bottom'}]} | ||
scales: { xAxes: [{ type: 'linear', position: 'bottom' }] } | ||
} | ||
}) | ||
}); | ||
|
||
const textualOutput = `${key}:\n\n` + data.points.map((p) => `${p.x}\t${p.y}`).join('\n') | ||
console.log(textualOutput) | ||
const textualOutput = | ||
`${key}:\n\n` + data.points.map(p => `${p.x}\t${p.y}`).join('\n'); | ||
console.log(textualOutput); | ||
} else { | ||
const title = document.createElement('h2') | ||
title.textContent = key | ||
benchmarkContainer.appendChild(title) | ||
const duration = document.createElement('p') | ||
duration.textContent = `${data.points[0].y}ms` | ||
benchmarkContainer.appendChild(duration) | ||
const title = document.createElement('h2'); | ||
title.textContent = key; | ||
benchmarkContainer.appendChild(title); | ||
const duration = document.createElement('p'); | ||
duration.textContent = `${data.points[0].y}ms`; | ||
benchmarkContainer.appendChild(duration); | ||
|
||
const textualOutput = `${key}: ${data.points[0].y}` | ||
console.log(textualOutput) | ||
const textualOutput = `${key}: ${data.points[0].y}`; | ||
console.log(textualOutput); | ||
} | ||
|
||
await global.atom.reset() | ||
await global.atom.reset(); | ||
} | ||
} | ||
|
||
return 0 | ||
} | ||
return 0; | ||
}; |
110 changes: 61 additions & 49 deletions
110
benchmarks/text-editor-large-file-construction.bench.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,100 @@ | ||
const {TextEditor, TextBuffer} = require('atom') | ||
const { TextEditor, TextBuffer } = require('atom'); | ||
|
||
const MIN_SIZE_IN_KB = 0 * 1024 | ||
const MAX_SIZE_IN_KB = 10 * 1024 | ||
const SIZE_STEP_IN_KB = 1024 | ||
const LINE_TEXT = 'Lorem ipsum dolor sit amet\n' | ||
const TEXT = LINE_TEXT.repeat(Math.ceil(MAX_SIZE_IN_KB * 1024 / LINE_TEXT.length)) | ||
const MIN_SIZE_IN_KB = 0 * 1024; | ||
const MAX_SIZE_IN_KB = 10 * 1024; | ||
const SIZE_STEP_IN_KB = 1024; | ||
const LINE_TEXT = 'Lorem ipsum dolor sit amet\n'; | ||
const TEXT = LINE_TEXT.repeat( | ||
Math.ceil((MAX_SIZE_IN_KB * 1024) / LINE_TEXT.length) | ||
); | ||
|
||
module.exports = async ({test}) => { | ||
const data = [] | ||
module.exports = async ({ test }) => { | ||
const data = []; | ||
|
||
document.body.appendChild(atom.workspace.getElement()) | ||
document.body.appendChild(atom.workspace.getElement()); | ||
|
||
atom.packages.loadPackages() | ||
await atom.packages.activate() | ||
atom.packages.loadPackages(); | ||
await atom.packages.activate(); | ||
|
||
for (let pane of atom.workspace.getPanes()) { | ||
pane.destroy() | ||
pane.destroy(); | ||
} | ||
|
||
for (let sizeInKB = MIN_SIZE_IN_KB; sizeInKB < MAX_SIZE_IN_KB; sizeInKB += SIZE_STEP_IN_KB) { | ||
const text = TEXT.slice(0, sizeInKB * 1024) | ||
console.log(text.length / 1024) | ||
|
||
let t0 = window.performance.now() | ||
const buffer = new TextBuffer({text}) | ||
const editor = new TextEditor({buffer, autoHeight: false, largeFileMode: true}) | ||
atom.grammars.autoAssignLanguageMode(buffer) | ||
atom.workspace.getActivePane().activateItem(editor) | ||
let t1 = window.performance.now() | ||
for ( | ||
let sizeInKB = MIN_SIZE_IN_KB; | ||
sizeInKB < MAX_SIZE_IN_KB; | ||
sizeInKB += SIZE_STEP_IN_KB | ||
) { | ||
const text = TEXT.slice(0, sizeInKB * 1024); | ||
console.log(text.length / 1024); | ||
|
||
let t0 = window.performance.now(); | ||
const buffer = new TextBuffer({ text }); | ||
const editor = new TextEditor({ | ||
buffer, | ||
autoHeight: false, | ||
largeFileMode: true | ||
}); | ||
atom.grammars.autoAssignLanguageMode(buffer); | ||
atom.workspace.getActivePane().activateItem(editor); | ||
let t1 = window.performance.now(); | ||
|
||
data.push({ | ||
name: 'Opening a large file', | ||
x: sizeInKB, | ||
duration: t1 - t0 | ||
}) | ||
}); | ||
|
||
const tickDurations = [] | ||
const tickDurations = []; | ||
for (let i = 0; i < 20; i++) { | ||
await timeout(50) | ||
t0 = window.performance.now() | ||
await timeout(0) | ||
t1 = window.performance.now() | ||
tickDurations[i] = t1 - t0 | ||
await timeout(50); | ||
t0 = window.performance.now(); | ||
await timeout(0); | ||
t1 = window.performance.now(); | ||
tickDurations[i] = t1 - t0; | ||
} | ||
|
||
data.push({ | ||
name: 'Max time event loop was blocked after opening a large file', | ||
x: sizeInKB, | ||
duration: Math.max(...tickDurations) | ||
}) | ||
}); | ||
|
||
t0 = window.performance.now() | ||
editor.setCursorScreenPosition(editor.element.screenPositionForPixelPosition({ | ||
top: 100, | ||
left: 30 | ||
})) | ||
t1 = window.performance.now() | ||
t0 = window.performance.now(); | ||
editor.setCursorScreenPosition( | ||
editor.element.screenPositionForPixelPosition({ | ||
top: 100, | ||
left: 30 | ||
}) | ||
); | ||
t1 = window.performance.now(); | ||
|
||
data.push({ | ||
name: 'Clicking the editor after opening a large file', | ||
x: sizeInKB, | ||
duration: t1 - t0 | ||
}) | ||
}); | ||
|
||
t0 = window.performance.now() | ||
editor.element.setScrollTop(editor.element.getScrollTop() + 100) | ||
t1 = window.performance.now() | ||
t0 = window.performance.now(); | ||
editor.element.setScrollTop(editor.element.getScrollTop() + 100); | ||
t1 = window.performance.now(); | ||
|
||
data.push({ | ||
name: 'Scrolling down after opening a large file', | ||
x: sizeInKB, | ||
duration: t1 - t0 | ||
}) | ||
}); | ||
|
||
editor.destroy() | ||
buffer.destroy() | ||
await timeout(10000) | ||
editor.destroy(); | ||
buffer.destroy(); | ||
await timeout(10000); | ||
} | ||
|
||
atom.workspace.getElement().remove() | ||
atom.workspace.getElement().remove(); | ||
|
||
return data | ||
} | ||
return data; | ||
}; | ||
|
||
function timeout (duration) { | ||
return new Promise((resolve) => setTimeout(resolve, duration)) | ||
function timeout(duration) { | ||
return new Promise(resolve => setTimeout(resolve, duration)); | ||
} |
Oops, something went wrong.