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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<html>
<head>
<title>DataSchema Tests</title>
</head>
<body class="yui3-skin-sam">
<h1>DataSchema Performance Tests</h1>
<p><select id="testSelector"></select> <input type="button" value="Run Test" id="btnRun" disabled=true></p>
<script type="text/javascript">
YUI({
filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min',
allowRollup: false,
useBrowserConsole: false
}).use("console", "profiler", "dump", "datatype", "dataschema", function(Y) {
// Set up the page
var btnRun = Y.one("#btnRun"),
selectTest = Y.one("#testSelector"),
allTests = [],
myConsole = new Y.Console().render();
btnRun.set("disabled", false);
Y.on("click", function(e){
run();
}, btnRun);
function register(testName, testFn) {
var index = allTests.length;
allTests[index] = testFn;
var optionEl = document.createElement("option");
optionEl.innerHTML = testName;
selectTest.appendChild(optionEl);
}
function run() {
var test = selectTest.get("value");
Y.log("Starting " + test, "info", "perf");
allTests[selectTest.get("selectedIndex")].apply(this);
Y.log(test + " completed", "info", "perf");
}
//Define tests
register("Test basic JSON schema parsing", function() {
// Setup
var schema = {
resultListLocator:"results",
resultFields: [
"id",
"firstname",
"lastname"
]
},
data_in = {
results: []
},
data_out, i=0, startTime, endTime;
// Populate data
for(; i<10000; i++) {
}
// The test
startTime = new Date();
endTime = new Date();
});
// Setup
var schema = {
resultListLocator: "level_one.level_two[1]",
resultFields: [
]
},
results = [],
data_in = {
level_one: {
level_two: [
"foo"
]
}
},
data_out, i=0, startTime, endTime;
// Populate data
for(; i<10000; i++) {
results[i] = {
"id": i,
"fruit":{
"goodforpie": [
{"name":"apple", "calories":"70"},
{"name":"banana", "calories":"70", "profile":{
"taste":["sweet"]
}
},
]
}
}
}
data_in.level_one.level_two[1] = results;
// The test
startTime = new Date();
data_out = Y.DataSchema.JSON.apply(schema, data_in);
endTime = new Date();
Y.log(endTime-startTime);
});
register("Test XML schema parsing", function() {
var schema = {
resultListLocator: "item",
resultFields: [{key:"type", locator:"@type"}, {key:"rank", parser:Y.DataType.Number.parse}, "name", {key:"subnameatt", locator:"subitem/name/@type"}, {key:"age", locator:"subitem/age", parser:"number"}]
},
data_in = "<myroot rootatt='5'><top>topvalue</top><second nested='nestedsecond' /><allitems><livehere>",
data_out, i=0, startTime, endTime;
//Populate data
for(; i<10000; i++) {
data_in += "<item type='foo'><name type='nametype0'>Abc</name><rank>"+i+"</rank><subitem><name type='subnametype0'>subABC</name><age>10</age></subitem></item>";
}
data_in += "</livehere></allitems></myroot>";
data_in = Y.DataType.XML.parse(data_in);
// The test
startTime = new Date();
endTime = new Date();
});
});
</script>
</body>
</html>