You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
2.4 KiB
JavaScript
119 lines
2.4 KiB
JavaScript
6 years ago
|
"use strict";
|
||
|
|
||
|
const benchmark = require("benchmark");
|
||
|
|
||
|
const dm = require("../src");
|
||
|
|
||
|
let Identity = dm.createType("Identity", {
|
||
|
label: dm.string(),
|
||
|
nickname: dm.string({
|
||
|
matches: /^[a-z0-9_-]+$/
|
||
|
}),
|
||
|
emailAddress: dm.string({
|
||
|
matches: /@/
|
||
|
}),
|
||
|
xmppAddress: dm.string({
|
||
|
matches: /@/
|
||
|
}).optional(),
|
||
|
notes: dm.string().optional()
|
||
|
});
|
||
|
|
||
|
let User = dm.createType("User", {
|
||
|
name: dm.string(),
|
||
|
isActive: dm.boolean(),
|
||
|
registrationDate: dm.instanceOf(Date),
|
||
|
misc: dm.either(
|
||
|
dm.string(),
|
||
|
dm.number()
|
||
|
),
|
||
|
// undefinedValue: dm.undefined(),
|
||
|
// nullValue: dm.null(),
|
||
|
// nothingValue: dm.nothing(),
|
||
|
age: dm.number({
|
||
|
minimum: 0
|
||
|
}),
|
||
|
luckyNumbers: dm.setOf(dm.number({
|
||
|
minimum: 1,
|
||
|
maximum: 42
|
||
|
})),
|
||
|
identities: dm.setOf(Identity),
|
||
|
mainIdentity: Identity,
|
||
|
codeWords: dm.mapOf(dm.string(), dm.string())
|
||
|
});
|
||
|
|
||
|
new benchmark.Suite()
|
||
|
.add("normal", () => {
|
||
|
let me = {
|
||
|
name: "Sven Slootweg",
|
||
|
isActive: true,
|
||
|
registrationDate: new Date(),
|
||
|
age: 26,
|
||
|
luckyNumbers: new Set([13, 42]),
|
||
|
misc: 42,
|
||
|
identities: new Set([
|
||
|
{
|
||
|
label: "primary",
|
||
|
nickname: "joepie91",
|
||
|
emailAddress: "admin@cryto.net",
|
||
|
xmppAddress: "joepie91@neko.im",
|
||
|
notes: "Main nickname"
|
||
|
},
|
||
|
{
|
||
|
label: "bot",
|
||
|
nickname: "botpie91",
|
||
|
emailAddress: "botpie91@cryto.net"
|
||
|
}
|
||
|
]),
|
||
|
mainIdentity: {
|
||
|
label: "primary",
|
||
|
nickname: "joepie91",
|
||
|
emailAddress: "admin@cryto.net",
|
||
|
xmppAddress: "joepie91@neko.im",
|
||
|
notes: "Main nickname"
|
||
|
},
|
||
|
codeWords: new Map([
|
||
|
["foo", "Foo"],
|
||
|
["bar", "Bar"]
|
||
|
])
|
||
|
};
|
||
|
})
|
||
|
.add("strict", () => {
|
||
|
let me = User({
|
||
|
name: "Sven Slootweg",
|
||
|
isActive: true,
|
||
|
registrationDate: new Date(),
|
||
|
age: 26,
|
||
|
luckyNumbers: new Set([13, 42]),
|
||
|
misc: 42,
|
||
|
identities: new Set([
|
||
|
Identity({
|
||
|
label: "primary",
|
||
|
nickname: "joepie91",
|
||
|
emailAddress: "admin@cryto.net",
|
||
|
xmppAddress: "joepie91@neko.im",
|
||
|
notes: "Main nickname"
|
||
|
}),
|
||
|
Identity({
|
||
|
label: "bot",
|
||
|
nickname: "botpie91",
|
||
|
emailAddress: "botpie91@cryto.net"
|
||
|
})
|
||
|
]),
|
||
|
mainIdentity: Identity({
|
||
|
label: "primary",
|
||
|
nickname: "joepie91",
|
||
|
emailAddress: "admin@cryto.net",
|
||
|
xmppAddress: "joepie91@neko.im",
|
||
|
notes: "Main nickname"
|
||
|
}),
|
||
|
codeWords: new Map([
|
||
|
["foo", "Foo"],
|
||
|
["bar", "Bar"]
|
||
|
])
|
||
|
});
|
||
|
})
|
||
|
.on("cycle", function (event) {
|
||
|
console.log(String(event.target));
|
||
|
})
|
||
|
.run();
|