Skip to content

Instantly share code, notes, and snippets.

@nathansobo
Created March 27, 2017 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansobo/10d08abc3bb0508e3f07f62069e1c322 to your computer and use it in GitHub Desktop.
Save nathansobo/10d08abc3bb0508e3f07f62069e1c322 to your computer and use it in GitHub Desktop.
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