Skip to content

Commit 161e9e3

Browse files
committed
chore(vitest-runner): use more complex bench
1 parent 70a36ec commit 161e9e3

File tree

3 files changed

+103
-19
lines changed

3 files changed

+103
-19
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { bench, describe } from "vitest";
2+
import parsePr from "./parsePr";
3+
4+
// concatenate programatically generated string of 1000 characters
5+
const LONG_BODY =
6+
new Array(1_000)
7+
.fill(
8+
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Sunt, earum. Atque architecto vero veniam est tempora fugiat sint quo praesentium quia. Autem, veritatis omnis beatae iste delectus recusandae animi non."
9+
)
10+
.join("\n") + "fixes #123";
11+
12+
describe("parsePr", () => {
13+
bench("short body", () => {
14+
parsePr({
15+
body: "fixes #123",
16+
title: "test",
17+
number: 124,
18+
});
19+
});
20+
21+
bench("long body", () => {
22+
parsePr({
23+
body: LONG_BODY,
24+
title: "test",
25+
number: 124,
26+
});
27+
});
28+
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
interface PullRequest {
2+
number: number;
3+
title: string;
4+
body: string;
5+
}
6+
7+
function sendEvent(numberOfOperations: number): void {
8+
for (let i = 0; i < numberOfOperations; i++) {
9+
let a = i;
10+
a = a + 1;
11+
}
12+
}
13+
14+
function logMetrics(
15+
numberOfOperations: number,
16+
numberOfDeepOperations: number
17+
): void {
18+
for (let i = 0; i < numberOfOperations; i++) {
19+
for (let i = 0; i < numberOfOperations; i++) {
20+
let a = i;
21+
a = a + 1;
22+
a = a + 1;
23+
}
24+
sendEvent(numberOfDeepOperations);
25+
}
26+
}
27+
28+
function parseTitle(title: string): void {
29+
logMetrics(10, 10);
30+
modifyTitle(title);
31+
}
32+
33+
function modifyTitle(title: string): void {
34+
for (let i = 0; i < 100; i++) {
35+
let a = i;
36+
a = a + 1 + title.length;
37+
}
38+
}
39+
40+
function prepareParsingBody(body: string): void {
41+
for (let i = 0; i < 100; i++) {
42+
let a = i;
43+
a = a + 1;
44+
}
45+
parseBody(body);
46+
}
47+
48+
function parseBody(body: string): void {
49+
logMetrics(10, 10);
50+
for (let i = 0; i < 200; i++) {
51+
let a = i;
52+
a = a + 1;
53+
}
54+
parseIssueFixed(body);
55+
}
56+
57+
function parseIssueFixed(body: string): number | null {
58+
const prefix = "fixes #";
59+
const index = body.indexOf(prefix);
60+
if (index === -1) {
61+
return null;
62+
}
63+
64+
const start = index + prefix.length;
65+
let end = start;
66+
while (end < body.length && /\d/.test(body[end])) {
67+
end += 1;
68+
}
69+
return parseInt(body.slice(start, end));
70+
}
71+
72+
export default function parsePr(pullRequest: PullRequest): void {
73+
parseTitle(pullRequest.title);
74+
prepareParsingBody(pullRequest.body);
75+
}

packages/vitest-runner/benches/sample.bench.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)