-
Notifications
You must be signed in to change notification settings - Fork 11
/
perf4.js
60 lines (47 loc) · 1.75 KB
/
perf4.js
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
import { LogicEngine } from './index.js'
const optimized = new LogicEngine()
const unoptimized = new LogicEngine(undefined, { disableInterpretedOptimization: true })
const dynamicRule = { '+': [1, 2, 3, { val: 'a' }] }
const staticRule = { '+': [1, 2, 3, 4] }
console.time('Optimized, Same Object, Dynamic')
for (let i = 0; i < 1e6; i++) {
optimized.run(dynamicRule, { a: i })
}
console.timeEnd('Optimized, Same Object, Dynamic')
console.time('Optimized, Same Object, Static')
for (let i = 0; i < 1e6; i++) {
optimized.run(staticRule)
}
console.timeEnd('Optimized, Same Object, Static')
console.time('Unoptimized, Same Object, Dynamic')
for (let i = 0; i < 1e6; i++) {
unoptimized.run(dynamicRule, { a: i })
}
console.timeEnd('Unoptimized, Same Object, Dynamic')
console.time('Unoptimized, Same Object, Static')
for (let i = 0; i < 1e6; i++) {
unoptimized.run(staticRule)
}
console.timeEnd('Unoptimized, Same Object, Static')
console.log('----')
console.time('Optimized, Different Object, Dynamic')
for (let i = 0; i < 1e6; i++) {
optimized.run({ '+': [1, 2, 3, { val: 'a' }] }, { a: i })
}
console.timeEnd('Optimized, Different Object, Dynamic')
optimized.disableInterpretedOptimization = false
console.time('Optimized, Different Object, Static')
for (let i = 0; i < 1e6; i++) {
optimized.run({ '+': [1, 2, 3, 4] })
}
console.timeEnd('Optimized, Different Object, Static')
console.time('Unoptimized, Different Object, Dynamic')
for (let i = 0; i < 1e6; i++) {
unoptimized.run({ '+': [1, 2, 3, { val: 'a' }] }, { a: i })
}
console.timeEnd('Unoptimized, Different Object, Dynamic')
console.time('Unoptimized, Different Object, Static')
for (let i = 0; i < 1e6; i++) {
unoptimized.run({ '+': [1, 2, 3, 4] })
}
console.timeEnd('Unoptimized, Different Object, Static')