Skip to content

Instantly share code, notes, and snippets.

@jerch
Created October 31, 2018 12:33
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 jerch/acca11c68bfe5c8172c909a1cb9fa6db to your computer and use it in GitHub Desktop.
Save jerch/acca11c68bfe5c8172c909a1cb9fa6db to your computer and use it in GitHub Desktop.
const Terminal = require('xterm/lib/Terminal').Terminal;
const pty = require('xterm/node_modules/node-pty');
const perfContext = require('../lib/index').perfContext;
const before = require('../lib/index').before;
const RuntimeCase = require('../lib/index').RuntimeCase;
class TestTerminal extends Terminal {
writeSync(data) {
this.writeBuffer.push(data);
this._innerWrite();
}
}
let content = '';
before(async () => {
// grab output from "ls -lR /usr/lib"
const p = pty.spawn('ls', ['--color=auto', '-lR', '/usr/lib'], {
name: 'xterm-color',
cols: 80,
rows: 25,
cwd: process.env.HOME,
env: process.env
});
p.on('data', data => { content += data; });
await new Promise(resolve => p.on('exit', () => resolve()));
});
perfContext('translateToString - JSArray', () => {
let terminal;
before(() => {
terminal = new TestTerminal({
cols: 80,
rows: 25,
scrollback: 10000,
experimentalBufferLineImpl: 'JSArray'
});
terminal.writeSync(content);
});
new RuntimeCase('', () => {
const strings = [];
for (let i = 0; i < terminal.buffer.lines.length; ++i) {
strings.push(terminal.buffer.translateBufferLineToString(i, true));
}
return strings;
}, {fork: true}).showRuntime().showAverageRuntime();
});
perfContext('translateToString - TypedArray', () => {
let terminal;
before(() => {
terminal = new TestTerminal({
cols: 80,
rows: 25,
scrollback: 10000,
experimentalBufferLineImpl: 'TypedArray'
});
terminal.writeSync(content);
});
new RuntimeCase('', () => {
const strings = [];
for (let i = 0; i < terminal.buffer.lines.length; ++i) {
strings.push(terminal.buffer.translateBufferLineToString(i, true));
}
return strings;
}, {fork: true}).showRuntime().showAverageRuntime();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment