-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathTerminal.benchmark.ts
68 lines (62 loc) · 2.23 KB
/
Terminal.benchmark.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* 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 'common/input/TextDecoder';
import { CoreBrowserTerminal } from 'browser/CoreBrowserTerminal';
perfContext('Terminal: ls -lR /usr/lib', () => {
let content = '';
let contentUtf8: Uint8Array;
before(async () => {
// grab output from "ls -lR /usr"
const p = spawn('ls', ['--color=auto', '-lR', '/usr/lib'], {
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.onData(data => {
chunks.push(data as unknown as Buffer);
length += data.length;
});
await new Promise<void>(resolve => p.onExit(() => 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/string/async', () => {
let terminal: CoreBrowserTerminal;
before(() => {
terminal = new CoreBrowserTerminal({ cols: 80, rows: 25, scrollback: 1000 });
});
new ThroughputRuntimeCase('', async () => {
await new Promise<void>(res => terminal.write(content, res));
return { payloadSize: contentUtf8.length };
}, { fork: false }).showAverageThroughput();
});
perfContext('write/Utf8/async', () => {
let terminal: CoreBrowserTerminal;
before(() => {
terminal = new CoreBrowserTerminal({ cols: 80, rows: 25, scrollback: 1000 });
});
new ThroughputRuntimeCase('', async () => {
await new Promise<void>(res => terminal.write(content, res));
return { payloadSize: contentUtf8.length };
}, { fork: false }).showAverageThroughput();
});
});