Files

69 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2019-06-07 21:39:07 +02:00
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
2019-06-06 15:46:52 +02:00
import { perfContext, before, ThroughputRuntimeCase } from 'xterm-benchmark';
import { spawn } from 'node-pty';
2019-06-09 17:31:57 +02:00
import { Utf8ToUtf32, stringFromCodePoint } from 'common/input/TextDecoder';
2024-07-05 08:46:15 -07:00
import { CoreBrowserTerminal } from 'browser/CoreBrowserTerminal';
2019-06-06 15:46:52 +02:00
2019-06-09 22:23:15 +02:00
perfContext('Terminal: ls -lR /usr/lib', () => {
2019-06-06 15:46:52 +02:00
let content = '';
let contentUtf8: Uint8Array;
before(async () => {
// grab output from "ls -lR /usr"
2019-06-09 22:23:15 +02:00
const p = spawn('ls', ['--color=auto', '-lR', '/usr/lib'], {
2019-06-07 21:39:07 +02:00
name: 'xterm-256color',
2019-06-06 15:46:52 +02:00
cols: 80,
rows: 25,
cwd: process.env.HOME,
env: process.env,
2019-06-09 14:51:44 +02:00
encoding: (null as unknown as string) // needs to be fixed in node-pty
2019-06-06 15:46:52 +02:00
});
const chunks: Buffer[] = [];
let length = 0;
2023-10-02 11:05:33 -07:00
p.onData(data => {
2019-06-06 15:46:52 +02: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-06-06 15:46:52 +02: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('write/string/async', () => {
2024-07-05 08:46:15 -07:00
let terminal: CoreBrowserTerminal;
2019-06-06 15:46:52 +02:00
before(() => {
2024-07-05 08:46:15 -07:00
terminal = new CoreBrowserTerminal({ cols: 80, rows: 25, scrollback: 1000 });
2019-06-06 15:46:52 +02:00
});
new ThroughputRuntimeCase('', async () => {
await new Promise<void>(res => terminal.write(content, res));
2021-08-12 12:59:22 -07:00
return { payloadSize: contentUtf8.length };
}, { fork: false }).showAverageThroughput();
2019-06-06 15:46:52 +02:00
});
perfContext('write/Utf8/async', () => {
2024-07-05 08:46:15 -07:00
let terminal: CoreBrowserTerminal;
2019-06-06 15:46:52 +02:00
before(() => {
2024-07-05 08:46:15 -07:00
terminal = new CoreBrowserTerminal({ cols: 80, rows: 25, scrollback: 1000 });
2019-06-06 15:46:52 +02:00
});
new ThroughputRuntimeCase('', async () => {
await new Promise<void>(res => terminal.write(content, res));
2021-08-12 12:59:22 -07:00
return { payloadSize: contentUtf8.length };
}, { fork: false }).showAverageThroughput();
2019-06-06 15:46:52 +02:00
});
});