-
Notifications
You must be signed in to change notification settings - Fork 2
/
decls_bench.ts
46 lines (39 loc) · 1.16 KB
/
decls_bench.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
import { SourceFile } from "../deps/ts_morph.ts"
import type { Declaration } from "./decl_deps.ts"
import { getDecls as getDeclsStream } from "./decls.ts"
import { getDeclExampleFile } from "./_example_project.ts"
/**
* @module
*
* benchmark to show that Rimbu Streams aren't slower than
* array-based counterparts. (1.01x faster/slower than array)
*
* using Rimbu Streams everywhere removes conversion overhead
*/
const getDeclsArray =
(filter: (node: Declaration) => boolean) =>
(files: SourceFile[]): Declaration[] =>
files.flatMap((file) =>
[
...file.getVariableDeclarations(),
...file.getFunctions(),
...file.getClasses(),
].filter(filter)
)
const filter = (node: Declaration) =>
!node.getName()?.toLowerCase().endsWith("ignore")
for (const n of [1, 10, 100]) {
const group = `(x${n})`
Deno.bench(`array ${group}`, { group, baseline: true }, (b) => {
const files = getDeclExampleFile(n)
b.start()
const _decls = getDeclsArray(filter)([files])
b.end()
})
Deno.bench(`stream ${group}`, { group }, (b) => {
const files = getDeclExampleFile(n)
b.start()
const _decls = getDeclsStream(filter)([files]).toArray()
b.end()
})
}