Files

66 lines
2.1 KiB
TypeScript
Raw Permalink Normal View History

2019-08-16 21:22:37 +08:00
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
2019-11-28 22:17:53 +08:00
import { perfContext, before, ThroughputRuntimeCase } from 'xterm-benchmark';
2019-08-16 21:22:37 +08:00
import { spawn } from 'node-pty';
import { Utf8ToUtf32, stringFromCodePoint } from 'common/input/TextDecoder';
2020-04-26 11:06:30 -07:00
import { Terminal } from 'browser/public/Terminal';
import { SerializeAddon } from 'SerializeAddon';
2019-08-16 21:22:37 +08:00
class TestTerminal extends Terminal {
2020-04-14 06:23:11 -07:00
public writeSync(data: string): void {
2020-03-28 07:37:21 -07:00
(this as any)._core.writeSync(data);
2019-08-16 21:22:37 +08:00
}
}
perfContext('Terminal: sh -c "dd if=/dev/urandom count=40 bs=1k | hexdump | lolcat -f"', () => {
2019-08-16 21:22:37 +08:00
let content = '';
let contentUtf8: Uint8Array;
before(async () => {
const p = spawn('sh', ['-c', 'dd if=/dev/urandom count=40 bs=1k | hexdump | lolcat -f'], {
2019-08-16 21:22:37 +08:00
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;
2023-10-02 11:05:33 -07:00
p.onData(data => {
2019-08-16 21:22:37 +08:00
chunks.push(data as unknown as Buffer);
length += data.length;
});
2023-10-02 11:05:33 -07:00
await new Promise<void>(resolve => p.onExit(() => resolve()));
2019-08-16 21:22:37 +08:00
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('serialize', () => {
let terminal: TestTerminal;
2019-11-28 22:17:53 +08:00
const serializeAddon = new SerializeAddon();
2019-08-16 21:22:37 +08:00
before(() => {
terminal = new TestTerminal({ cols: 80, rows: 25, scrollback: 5000 });
serializeAddon.activate(terminal);
terminal.writeSync(content);
});
new ThroughputRuntimeCase('', () => {
return { payloadSize: serializeAddon.serialize().length };
}, { fork: false }).showAverageThroughput();
});
});