objectmodel 4.4.4 → 4.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +8 -8
- package/.eslintrc.json +25 -25
- package/LICENSE +22 -22
- package/README.md +67 -67
- package/build/add-banner.js +13 -13
- package/build/bundle-entry.dev.js +2 -2
- package/build/bundle-entry.js +11 -11
- package/build/update-docs.js +1 -1
- package/dist/object-model.cjs +111 -110
- package/dist/object-model.js +86 -83
- package/dist/object-model.js.map +1 -1
- package/dist/object-model.min.js +4 -2
- package/dist/object-model.min.js.map +1 -1
- package/index.html +4 -4
- package/package.json +74 -70
- package/rollup.config.js +13 -13
- package/src/helpers.js +43 -43
- package/src/list-model.js +43 -43
- package/src/object-model.d.ts +11 -10
- package/src/object-model.js +1 -0
- package/test/basic-model.spec.cjs +272 -272
- package/test/basic-model.test-d.ts +1 -0
- package/test/bench/array.html +51 -51
- package/test/bench/bench-lib.js +49 -49
- package/test/bench/map-no-cast.html +53 -53
- package/test/bench/map-set.html +52 -52
- package/test/bench/map.html +51 -51
- package/test/bench/object-models.html +87 -87
- package/test/index.cjs +13 -13
- package/test/map-model.spec.cjs +236 -236
- package/test/model.spec.cjs +30 -30
- package/test/object-model.spec.cjs +2 -1
- package/test/object-model.test-d.ts +9 -2
- package/test/set-model.spec.cjs +222 -222
- package/test/umd.html +25 -25
- package/types/index.d.ts +3 -1
package/test/bench/array.html
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<title>Benchmark: Array Models</title>
|
|
5
|
-
</head>
|
|
6
|
-
|
|
7
|
-
<body>
|
|
8
|
-
<h1>Benchmark: Array Models</h1>
|
|
9
|
-
</body>
|
|
10
|
-
|
|
11
|
-
<script src="bench-lib.js"></script>
|
|
12
|
-
|
|
13
|
-
<script type="module">
|
|
14
|
-
import { Model, BasicModel, ObjectModel, ArrayModel } from "../../src/index.js"
|
|
15
|
-
|
|
16
|
-
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
-
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
-
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
-
|
|
20
|
-
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
-
let mockOM = () => Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() })))
|
|
22
|
-
let mockAMData = n => (new Array(n)).fill(0).map(x => mockOM())
|
|
23
|
-
|
|
24
|
-
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
-
|
|
26
|
-
class OM extends ObjectModel({
|
|
27
|
-
id0: [Id],
|
|
28
|
-
id1: [Id],
|
|
29
|
-
id2: [Id],
|
|
30
|
-
id3: [Id],
|
|
31
|
-
id4: [Id],
|
|
32
|
-
id5: [Id],
|
|
33
|
-
id6: [Id],
|
|
34
|
-
id7: [Id],
|
|
35
|
-
id8: [Id],
|
|
36
|
-
id9: [Id]
|
|
37
|
-
}) { };
|
|
38
|
-
|
|
39
|
-
const AM = ArrayModel(OM)
|
|
40
|
-
|
|
41
|
-
bench([100, 1000, 10000].map(n => ({
|
|
42
|
-
description: `Init ArrayModel with ${n} elements`,
|
|
43
|
-
nbIter: 3,
|
|
44
|
-
run() {
|
|
45
|
-
const data = mockAMData(n);
|
|
46
|
-
new AM(data)
|
|
47
|
-
}
|
|
48
|
-
})))
|
|
49
|
-
|
|
50
|
-
</script>
|
|
51
|
-
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<title>Benchmark: Array Models</title>
|
|
5
|
+
</head>
|
|
6
|
+
|
|
7
|
+
<body>
|
|
8
|
+
<h1>Benchmark: Array Models</h1>
|
|
9
|
+
</body>
|
|
10
|
+
|
|
11
|
+
<script src="bench-lib.js"></script>
|
|
12
|
+
|
|
13
|
+
<script type="module">
|
|
14
|
+
import { Model, BasicModel, ObjectModel, ArrayModel } from "../../src/index.js"
|
|
15
|
+
|
|
16
|
+
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
+
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
+
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
+
|
|
20
|
+
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
+
let mockOM = () => Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() })))
|
|
22
|
+
let mockAMData = n => (new Array(n)).fill(0).map(x => mockOM())
|
|
23
|
+
|
|
24
|
+
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
+
|
|
26
|
+
class OM extends ObjectModel({
|
|
27
|
+
id0: [Id],
|
|
28
|
+
id1: [Id],
|
|
29
|
+
id2: [Id],
|
|
30
|
+
id3: [Id],
|
|
31
|
+
id4: [Id],
|
|
32
|
+
id5: [Id],
|
|
33
|
+
id6: [Id],
|
|
34
|
+
id7: [Id],
|
|
35
|
+
id8: [Id],
|
|
36
|
+
id9: [Id]
|
|
37
|
+
}) { };
|
|
38
|
+
|
|
39
|
+
const AM = ArrayModel(OM)
|
|
40
|
+
|
|
41
|
+
bench([100, 1000, 10000].map(n => ({
|
|
42
|
+
description: `Init ArrayModel with ${n} elements`,
|
|
43
|
+
nbIter: 3,
|
|
44
|
+
run() {
|
|
45
|
+
const data = mockAMData(n);
|
|
46
|
+
new AM(data)
|
|
47
|
+
}
|
|
48
|
+
})))
|
|
49
|
+
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
52
|
</html>
|
package/test/bench/bench-lib.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
let table = document.createElement("table")
|
|
2
|
-
document.body.appendChild(table)
|
|
3
|
-
|
|
4
|
-
const bench = tests => {
|
|
5
|
-
let t0 = performance.now();
|
|
6
|
-
bench1(tests, 0, () => {
|
|
7
|
-
console.log(`Finished tests in ${(performance.now() - t0).toFixed(0)} ms`)
|
|
8
|
-
console.log(tests);
|
|
9
|
-
})
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const bench1 = (tests, i, onFinish) => {
|
|
13
|
-
let test = tests[i] = Object.assign({
|
|
14
|
-
nbIter: 10,
|
|
15
|
-
description: tests[i].run.name,
|
|
16
|
-
done: false,
|
|
17
|
-
times: [],
|
|
18
|
-
tr: table.insertRow()
|
|
19
|
-
}, tests[i]);
|
|
20
|
-
|
|
21
|
-
iter(test, 0, () => {
|
|
22
|
-
let averageTime = test.times.reduce((a, b) => a + b, 0) / test.nbIter;
|
|
23
|
-
log(test, averageTime.toFixed(3) + " ms")
|
|
24
|
-
|
|
25
|
-
if (i < tests.length - 1) {
|
|
26
|
-
setTimeout(() => bench1(tests, i + 1, onFinish), 10)
|
|
27
|
-
} else {
|
|
28
|
-
onFinish()
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const iter = (test, i, onFinish) => {
|
|
34
|
-
log(test, `test ${i + 1} / ${test.nbIter}`)
|
|
35
|
-
|
|
36
|
-
let t0 = performance.now();
|
|
37
|
-
test.run();
|
|
38
|
-
test.times.push(performance.now() - t0)
|
|
39
|
-
|
|
40
|
-
if (i < test.nbIter - 1) {
|
|
41
|
-
setTimeout(() => iter(test, i + 1, onFinish), 10);
|
|
42
|
-
} else {
|
|
43
|
-
test.done = true;
|
|
44
|
-
onFinish();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const log = (test, msg) => { test.tr.textContent = test.description + ": " + msg }
|
|
49
|
-
|
|
1
|
+
let table = document.createElement("table")
|
|
2
|
+
document.body.appendChild(table)
|
|
3
|
+
|
|
4
|
+
const bench = tests => {
|
|
5
|
+
let t0 = performance.now();
|
|
6
|
+
bench1(tests, 0, () => {
|
|
7
|
+
console.log(`Finished tests in ${(performance.now() - t0).toFixed(0)} ms`)
|
|
8
|
+
console.log(tests);
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const bench1 = (tests, i, onFinish) => {
|
|
13
|
+
let test = tests[i] = Object.assign({
|
|
14
|
+
nbIter: 10,
|
|
15
|
+
description: tests[i].run.name,
|
|
16
|
+
done: false,
|
|
17
|
+
times: [],
|
|
18
|
+
tr: table.insertRow()
|
|
19
|
+
}, tests[i]);
|
|
20
|
+
|
|
21
|
+
iter(test, 0, () => {
|
|
22
|
+
let averageTime = test.times.reduce((a, b) => a + b, 0) / test.nbIter;
|
|
23
|
+
log(test, averageTime.toFixed(3) + " ms")
|
|
24
|
+
|
|
25
|
+
if (i < tests.length - 1) {
|
|
26
|
+
setTimeout(() => bench1(tests, i + 1, onFinish), 10)
|
|
27
|
+
} else {
|
|
28
|
+
onFinish()
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const iter = (test, i, onFinish) => {
|
|
34
|
+
log(test, `test ${i + 1} / ${test.nbIter}`)
|
|
35
|
+
|
|
36
|
+
let t0 = performance.now();
|
|
37
|
+
test.run();
|
|
38
|
+
test.times.push(performance.now() - t0)
|
|
39
|
+
|
|
40
|
+
if (i < test.nbIter - 1) {
|
|
41
|
+
setTimeout(() => iter(test, i + 1, onFinish), 10);
|
|
42
|
+
} else {
|
|
43
|
+
test.done = true;
|
|
44
|
+
onFinish();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const log = (test, msg) => { test.tr.textContent = test.description + ": " + msg }
|
|
49
|
+
|
|
50
50
|
if(typeof window !== undefined) Object.assign(window, { bench, bench1 })
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<title>Benchmark: Map Models without autocast</title>
|
|
5
|
-
</head>
|
|
6
|
-
|
|
7
|
-
<body>
|
|
8
|
-
<h1>Benchmark: Map Models without autocast</h1>
|
|
9
|
-
</body>
|
|
10
|
-
|
|
11
|
-
<script src="bench-lib.js"></script>
|
|
12
|
-
|
|
13
|
-
<script type="module">
|
|
14
|
-
import { Model, BasicModel, ObjectModel, MapModel } from "../../src/index.js"
|
|
15
|
-
|
|
16
|
-
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
-
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
-
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
-
|
|
20
|
-
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
-
let mockOM = () => new OM(Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() }))))
|
|
22
|
-
let mockOMapData = n => (new Array(n)).fill(0).map((x, i) => [i, mockOM()])
|
|
23
|
-
|
|
24
|
-
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
-
|
|
26
|
-
class OM extends ObjectModel({
|
|
27
|
-
id0: [Id],
|
|
28
|
-
id0: [Id],
|
|
29
|
-
id1: [Id],
|
|
30
|
-
id2: [Id],
|
|
31
|
-
id3: [Id],
|
|
32
|
-
id4: [Id],
|
|
33
|
-
id5: [Id],
|
|
34
|
-
id6: [Id],
|
|
35
|
-
id7: [Id],
|
|
36
|
-
id8: [Id],
|
|
37
|
-
id9: [Id]
|
|
38
|
-
}) { };
|
|
39
|
-
|
|
40
|
-
const OMap = MapModel(Id, OM)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
bench([100, 1000, 10000].map(n => ({
|
|
44
|
-
description: `Init MapModel with ${n} elements`,
|
|
45
|
-
nbIter: 10,
|
|
46
|
-
run() {
|
|
47
|
-
const data = mockOMapData(n);
|
|
48
|
-
new OMap(data)
|
|
49
|
-
}
|
|
50
|
-
})))
|
|
51
|
-
|
|
52
|
-
</script>
|
|
53
|
-
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<title>Benchmark: Map Models without autocast</title>
|
|
5
|
+
</head>
|
|
6
|
+
|
|
7
|
+
<body>
|
|
8
|
+
<h1>Benchmark: Map Models without autocast</h1>
|
|
9
|
+
</body>
|
|
10
|
+
|
|
11
|
+
<script src="bench-lib.js"></script>
|
|
12
|
+
|
|
13
|
+
<script type="module">
|
|
14
|
+
import { Model, BasicModel, ObjectModel, MapModel } from "../../src/index.js"
|
|
15
|
+
|
|
16
|
+
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
+
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
+
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
+
|
|
20
|
+
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
+
let mockOM = () => new OM(Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() }))))
|
|
22
|
+
let mockOMapData = n => (new Array(n)).fill(0).map((x, i) => [i, mockOM()])
|
|
23
|
+
|
|
24
|
+
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
+
|
|
26
|
+
class OM extends ObjectModel({
|
|
27
|
+
id0: [Id],
|
|
28
|
+
id0: [Id],
|
|
29
|
+
id1: [Id],
|
|
30
|
+
id2: [Id],
|
|
31
|
+
id3: [Id],
|
|
32
|
+
id4: [Id],
|
|
33
|
+
id5: [Id],
|
|
34
|
+
id6: [Id],
|
|
35
|
+
id7: [Id],
|
|
36
|
+
id8: [Id],
|
|
37
|
+
id9: [Id]
|
|
38
|
+
}) { };
|
|
39
|
+
|
|
40
|
+
const OMap = MapModel(Id, OM)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
bench([100, 1000, 10000].map(n => ({
|
|
44
|
+
description: `Init MapModel with ${n} elements`,
|
|
45
|
+
nbIter: 10,
|
|
46
|
+
run() {
|
|
47
|
+
const data = mockOMapData(n);
|
|
48
|
+
new OMap(data)
|
|
49
|
+
}
|
|
50
|
+
})))
|
|
51
|
+
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
54
|
</html>
|
package/test/bench/map-set.html
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<title>Benchmark: Map Models, set one by one</title>
|
|
5
|
-
</head>
|
|
6
|
-
|
|
7
|
-
<body>
|
|
8
|
-
<h1>Benchmark: Map Models, set one by one</h1>
|
|
9
|
-
</body>
|
|
10
|
-
|
|
11
|
-
<script src="bench-lib.js"></script>
|
|
12
|
-
|
|
13
|
-
<script type="module">
|
|
14
|
-
import { Model, BasicModel, ObjectModel, MapModel } from "../../src/index.js"
|
|
15
|
-
|
|
16
|
-
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
-
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
-
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
-
|
|
20
|
-
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
-
let mockOM = () => Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() })))
|
|
22
|
-
let mockOMapData = n => (new Array(n)).fill(0).map((x, i) => [i, mockOM()])
|
|
23
|
-
|
|
24
|
-
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
-
|
|
26
|
-
class OM extends ObjectModel({
|
|
27
|
-
id0: [Id],
|
|
28
|
-
id1: [Id],
|
|
29
|
-
id2: [Id],
|
|
30
|
-
id3: [Id],
|
|
31
|
-
id4: [Id],
|
|
32
|
-
id5: [Id],
|
|
33
|
-
id6: [Id],
|
|
34
|
-
id7: [Id],
|
|
35
|
-
id8: [Id],
|
|
36
|
-
id9: [Id]
|
|
37
|
-
}) { };
|
|
38
|
-
|
|
39
|
-
const OMap = MapModel(Id, OM)
|
|
40
|
-
|
|
41
|
-
bench([100, 1000, 10000].map(n => ({
|
|
42
|
-
description: `Init MapModel with ${n} elements`,
|
|
43
|
-
nbIter: 10,
|
|
44
|
-
run() {
|
|
45
|
-
const data = mockOMapData(n);
|
|
46
|
-
const map = new OMap([])
|
|
47
|
-
for (let [key, value] of data) map.set(key, value)
|
|
48
|
-
}
|
|
49
|
-
})))
|
|
50
|
-
|
|
51
|
-
</script>
|
|
52
|
-
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<title>Benchmark: Map Models, set one by one</title>
|
|
5
|
+
</head>
|
|
6
|
+
|
|
7
|
+
<body>
|
|
8
|
+
<h1>Benchmark: Map Models, set one by one</h1>
|
|
9
|
+
</body>
|
|
10
|
+
|
|
11
|
+
<script src="bench-lib.js"></script>
|
|
12
|
+
|
|
13
|
+
<script type="module">
|
|
14
|
+
import { Model, BasicModel, ObjectModel, MapModel } from "../../src/index.js"
|
|
15
|
+
|
|
16
|
+
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
+
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
+
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
+
|
|
20
|
+
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
+
let mockOM = () => Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() })))
|
|
22
|
+
let mockOMapData = n => (new Array(n)).fill(0).map((x, i) => [i, mockOM()])
|
|
23
|
+
|
|
24
|
+
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
+
|
|
26
|
+
class OM extends ObjectModel({
|
|
27
|
+
id0: [Id],
|
|
28
|
+
id1: [Id],
|
|
29
|
+
id2: [Id],
|
|
30
|
+
id3: [Id],
|
|
31
|
+
id4: [Id],
|
|
32
|
+
id5: [Id],
|
|
33
|
+
id6: [Id],
|
|
34
|
+
id7: [Id],
|
|
35
|
+
id8: [Id],
|
|
36
|
+
id9: [Id]
|
|
37
|
+
}) { };
|
|
38
|
+
|
|
39
|
+
const OMap = MapModel(Id, OM)
|
|
40
|
+
|
|
41
|
+
bench([100, 1000, 10000].map(n => ({
|
|
42
|
+
description: `Init MapModel with ${n} elements`,
|
|
43
|
+
nbIter: 10,
|
|
44
|
+
run() {
|
|
45
|
+
const data = mockOMapData(n);
|
|
46
|
+
const map = new OMap([])
|
|
47
|
+
for (let [key, value] of data) map.set(key, value)
|
|
48
|
+
}
|
|
49
|
+
})))
|
|
50
|
+
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
53
|
</html>
|
package/test/bench/map.html
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<title>Benchmark: Map Models</title>
|
|
5
|
-
</head>
|
|
6
|
-
|
|
7
|
-
<body>
|
|
8
|
-
<h1>Benchmark: Map Models</h1>
|
|
9
|
-
</body>
|
|
10
|
-
|
|
11
|
-
<script src="bench-lib.js"></script>
|
|
12
|
-
|
|
13
|
-
<script type="module">
|
|
14
|
-
import { Model, BasicModel, ObjectModel, MapModel } from "../../src/index.js"
|
|
15
|
-
|
|
16
|
-
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
-
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
-
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
-
|
|
20
|
-
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
-
let mockOM = () => Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() })))
|
|
22
|
-
let mockOMapData = n => (new Array(n)).fill(0).map((x, i) => [i, mockOM()])
|
|
23
|
-
|
|
24
|
-
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
-
|
|
26
|
-
class OM extends ObjectModel({
|
|
27
|
-
id0: [Id],
|
|
28
|
-
id1: [Id],
|
|
29
|
-
id2: [Id],
|
|
30
|
-
id3: [Id],
|
|
31
|
-
id4: [Id],
|
|
32
|
-
id5: [Id],
|
|
33
|
-
id6: [Id],
|
|
34
|
-
id7: [Id],
|
|
35
|
-
id8: [Id],
|
|
36
|
-
id9: [Id]
|
|
37
|
-
}) { };
|
|
38
|
-
|
|
39
|
-
const OMap = MapModel(Id, OM)
|
|
40
|
-
|
|
41
|
-
bench([100, 1000, 10000].map(n => ({
|
|
42
|
-
description: `Init MapModel with ${n} elements`,
|
|
43
|
-
nbIter: 10,
|
|
44
|
-
run() {
|
|
45
|
-
const data = mockOMapData(n);
|
|
46
|
-
new OMap(data)
|
|
47
|
-
}
|
|
48
|
-
})))
|
|
49
|
-
|
|
50
|
-
</script>
|
|
51
|
-
|
|
1
|
+
<html>
|
|
2
|
+
|
|
3
|
+
<head>
|
|
4
|
+
<title>Benchmark: Map Models</title>
|
|
5
|
+
</head>
|
|
6
|
+
|
|
7
|
+
<body>
|
|
8
|
+
<h1>Benchmark: Map Models</h1>
|
|
9
|
+
</body>
|
|
10
|
+
|
|
11
|
+
<script src="bench-lib.js"></script>
|
|
12
|
+
|
|
13
|
+
<script type="module">
|
|
14
|
+
import { Model, BasicModel, ObjectModel, MapModel } from "../../src/index.js"
|
|
15
|
+
|
|
16
|
+
const Integer = BasicModel(Number).assert(Number.isInteger).as("Integer");
|
|
17
|
+
const PositiveNumber = BasicModel(Number).assert(function isPositive(n) { return n >= 0 }).as("PositiveNumber")
|
|
18
|
+
const PositiveInteger = PositiveNumber.extend().assert(Number.isInteger).as("PositiveInteger");
|
|
19
|
+
|
|
20
|
+
let mockId = () => Math.ceil(Math.random() * 100)
|
|
21
|
+
let mockOM = () => Object.assign({}, ...Array(10).fill().map((x, i) => ({ ["id" + i]: mockId() })))
|
|
22
|
+
let mockOMapData = n => (new Array(n)).fill(0).map((x, i) => [i, mockOM()])
|
|
23
|
+
|
|
24
|
+
const Id = PositiveInteger.extend().as('Id');
|
|
25
|
+
|
|
26
|
+
class OM extends ObjectModel({
|
|
27
|
+
id0: [Id],
|
|
28
|
+
id1: [Id],
|
|
29
|
+
id2: [Id],
|
|
30
|
+
id3: [Id],
|
|
31
|
+
id4: [Id],
|
|
32
|
+
id5: [Id],
|
|
33
|
+
id6: [Id],
|
|
34
|
+
id7: [Id],
|
|
35
|
+
id8: [Id],
|
|
36
|
+
id9: [Id]
|
|
37
|
+
}) { };
|
|
38
|
+
|
|
39
|
+
const OMap = MapModel(Id, OM)
|
|
40
|
+
|
|
41
|
+
bench([100, 1000, 10000].map(n => ({
|
|
42
|
+
description: `Init MapModel with ${n} elements`,
|
|
43
|
+
nbIter: 10,
|
|
44
|
+
run() {
|
|
45
|
+
const data = mockOMapData(n);
|
|
46
|
+
new OMap(data)
|
|
47
|
+
}
|
|
48
|
+
})))
|
|
49
|
+
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
52
|
</html>
|