FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
json-rules-engine/test/performance.test.js at master · CacheControl/json-rules-engine · GitHub
CacheControl
/
json-rules-engine
Public
Notifications
You must be signed in to change notification settings
Fork
507
Star
3.1k
Code
Issues
61
Pull requests
7
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
json-rules-engine
/
test
/
performance.test.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (60 loc) · 1.56 KB
Breadcrumbs
json-rules-engine
/
test
/
performance.test.js
Copy path
File metadata and controls
65 lines (60 loc) · 1.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
'use strict'
import
engineFactory
from
'../src/index'
import
perfy
from
'perfy'
import
deepClone
from
'clone'
describe
(
'Performance'
,
(
)
=>
{
const
baseConditions
=
{
any
:
[
{
fact
:
'age'
,
operator
:
'lessThan'
,
value
:
50
}
,
{
fact
:
'segment'
,
operator
:
'equal'
,
value
:
'european'
}
]
}
const
event
=
{
type
:
'ageTrigger'
,
params
:
{
demographic
:
'under50'
}
}
/*
* Generates an array of integers of length 'num'
*/
function
range
(
num
)
{
return
Array
.
from
(
Array
(
num
)
.
keys
(
)
)
}
function
setup
(
conditions
)
{
const
engine
=
engineFactory
(
)
const
config
=
deepClone
(
{
conditions
,
event
}
)
range
(
1000
)
.
forEach
(
(
)
=>
{
const
rule
=
factories
.
rule
(
config
)
engine
.
addRule
(
rule
)
}
)
engine
.
addFact
(
'segment'
,
'european'
,
{
cache
:
true
}
)
engine
.
addFact
(
'age'
,
15
,
{
cache
:
true
}
)
return
engine
}
it
(
'performs "any" quickly'
,
async
(
)
=>
{
const
engine
=
setup
(
baseConditions
)
perfy
.
start
(
'any'
)
await
engine
.
run
(
)
const
result
=
perfy
.
end
(
'any'
)
expect
(
result
.
time
)
.
to
.
be
.
greaterThan
(
0.001
)
expect
(
result
.
time
)
.
to
.
be
.
lessThan
(
0.5
)
}
)
it
(
'performs "all" quickly'
,
async
(
)
=>
{
const
conditions
=
deepClone
(
baseConditions
)
conditions
.
all
=
conditions
.
any
delete
conditions
.
any
const
engine
=
setup
(
conditions
)
perfy
.
start
(
'all'
)
await
engine
.
run
(
)
const
result
=
perfy
.
end
(
'all'
)
expect
(
result
.
time
)
.
to
.
be
.
greaterThan
(
0.001
)
// assert lower value
expect
(
result
.
time
)
.
to
.
be
.
lessThan
(
0.5
)
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL