-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathbenchmark.ts
More file actions
43 lines (39 loc) · 968 Bytes
/
benchmark.ts
File metadata and controls
43 lines (39 loc) · 968 Bytes
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
import { OrderDirection } from "./src/lib/config/CommonConfig"
import { ThreadOrderField } from "./src/lib/config/ThreadConfig"
import { ThreadProcessor } from "./src/lib/processors/ThreadProcessor"
let getCalls = 0
class MockThread {
constructor(
private id: string,
private date: Date,
private subject: string,
) {}
getId() {
getCalls++
return this.id
}
getLastMessageDate() {
getCalls++
return this.date
}
getFirstMessageSubject() {
getCalls++
return this.subject
}
}
const threads = Array.from(
{ length: 1000 },
(_, i) =>
new MockThread(`id-${i}`, new Date(2020, 0, i % 30), `Subject ${i % 100}`),
)
const start = Date.now()
ThreadProcessor.ordered(
threads as any,
{
orderBy: ThreadOrderField.LAST_MESSAGE_DATE,
orderDirection: OrderDirection.ASC,
},
ThreadProcessor.orderRules,
)
const end = Date.now()
console.log(`Total getter calls: ${getCalls}, Time taken: ${end - start} ms`)