Created
March 27, 2017 17:51
-
-
Save nathansobo/10d08abc3bb0508e3f07f62069e1c322 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const fs = require('fs') | |
global.profileEditor = async function () { | |
const sampleText = fs.readFileSync('/Users/nathan/src/atom/spec/fixtures/sample.js', 'utf8') + '\n' | |
// await profileScrollFullScreen() | |
// await timeoutPromise(500) | |
// await profileScrollHalfScreen() | |
// await timeoutPromise(500) | |
await profileCharacterInsertion() | |
async function profileScrollFullScreen () { | |
const editor = await openEditor() | |
const {component} = editor | |
console.time('scroll full screen') | |
for (let i = 0; i < 50; i++) { | |
if (i % 2 === 0) { | |
component.setScrollBottom(component.getScrollHeight()) | |
await updateComponent(component) | |
} else { | |
component.setScrollTop(0) | |
await updateComponent(component) | |
} | |
} | |
console.timeEnd('scroll full screen') | |
editor.destroy() | |
} | |
async function profileScrollHalfScreen () { | |
const editor = await openEditor() | |
const {component} = editor | |
console.time('scroll half screen') | |
for (let i = 0; i < 50; i++) { | |
component.setScrollTop(component.getScrollTop() + component.getScrollContainerClientHeight() / 2) | |
await updateComponent(component) | |
} | |
console.timeEnd('scroll half screen') | |
editor.destroy() | |
} | |
async function profileCharacterInsertion () { | |
const editor = await openEditor() | |
const {component} = editor | |
editor.setCursorScreenPosition([3, Infinity]) | |
console.time('insert and delete character') | |
for (let i = 0; i < 50; i++) { | |
editor.insertText('//') | |
await updateComponent(component) | |
await timeoutPromise(10) | |
editor.backspace() | |
editor.backspace() | |
await updateComponent(component) | |
await timeoutPromise(10) | |
} | |
console.timeEnd('insert and delete character') | |
editor.destroy() | |
} | |
function timeoutPromise (timeout) { | |
return new Promise(function (resolve) { | |
window.setTimeout(resolve, timeout) | |
}) | |
} | |
async function openEditor () { | |
await atom.workspace.open('/tmp/test.js') | |
const editor = atom.workspace.getActiveTextEditor() | |
editor.setText(sampleText.repeat(100)) | |
return new Promise((resolve) => { | |
editor.onDidTokenize(() => resolve(editor)) | |
}) | |
} | |
function updateComponent (component) { | |
component.scheduleUpdate() | |
return component.getNextUpdatePromise() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment