Files
xterm.js/benchmark-tests/Terminal.benchmark.ts
T
Jörg Breitbart 674914bbb7 moving benchmarks out of './src':
Harder than I thought for several reasons:
- need access to common to tests the subparts, thus the unified tsconfig
  in tests does not work (need the path translation to those parts)
- moving next to src I cannot use direct imports anymore (source files
  are out of rootDir), thus have to rely on d.ts files in out which is
  quite suboptimal as many parts do not expose the declaration files
  (can only type Terminal as any atm)
- compiler output has to resemble the '../out/..' import logic of the TS
  files or require fails, thus moved the ouput to './benchmark' for now

Conclusion: Not yet there, maybe not a good idea at all to move those
tests out of './src' as they heavily rely on not exported internals.
Needs more fiddling with the repo structure.
2019-06-09 14:51:44 +02:00

84 lines
2.4 KiB
TypeScript

/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { perfContext, before, ThroughputRuntimeCase } from 'xterm-benchmark';
import { spawn } from 'node-pty';
import { Utf8ToUtf32, stringFromCodePoint } from '../out/common/input/TextDecoder';
const Terminal: any = require('../out/Terminal').Terminal;
class TestTerminal extends Terminal {
constructor(opts: any) {
super(opts);
}
writeSync(data: string): void {
this.writeBuffer.push(data);
(this as any)._innerWrite();
}
writeSyncUtf8(data: Uint8Array): void {
(this as any).writeBufferUtf8.push(data);
(this as any)._innerWriteUtf8();
}
}
perfContext('Terminal: ls -lR /usr', () => {
let content = '';
let contentUtf8: Uint8Array;
before(async () => {
// grab output from "ls -lR /usr"
const p = spawn('ls', ['--color=auto', '-lR', '/usr'], {
name: 'xterm-256color',
cols: 80,
rows: 25,
cwd: process.env.HOME,
env: process.env,
encoding: (null as unknown as string) // needs to be fixed in node-pty
});
const chunks: Buffer[] = [];
let length = 0;
p.on('data', data => {
chunks.push(data as unknown as Buffer);
length += data.length;
});
await new Promise(resolve => p.on('exit', () => resolve()));
contentUtf8 = Buffer.concat(chunks, length);
// translate to content string
const buffer = new Uint32Array(contentUtf8.length);
const decoder = new Utf8ToUtf32();
const codepoints = decoder.decode(contentUtf8, buffer);
for (let i = 0; i < codepoints; ++i) {
content += stringFromCodePoint(buffer[i]);
// peek into content to force flat repr in v8
if (!(i % 10000000)) {
content[i];
}
}
});
perfContext('write', () => {
let terminal: TestTerminal;
before(() => {
terminal = new TestTerminal({cols: 80, rows: 25, scrollback: 1000});
});
new ThroughputRuntimeCase('', () => {
terminal.writeSync(content);
return {payloadSize: contentUtf8.length};
}, {fork: false}).showAverageThroughput();
});
perfContext('writeUtf8', () => {
let terminal: TestTerminal;
before(() => {
terminal = new TestTerminal({cols: 80, rows: 25, scrollback: 1000});
});
new ThroughputRuntimeCase('', () => {
terminal.writeSyncUtf8(contentUtf8);
return {payloadSize: contentUtf8.length};
}, {fork: false}).showAverageThroughput();
});
});