-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
58 lines (45 loc) · 1.63 KB
/
test.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
var cache = require("./js0n-cache");
var fs = require("fs");
var doSubKeyTest = false;
var data = fs.readFileSync("medium.json").toString("utf8");
var startTime = Date.now();
for (var i = 0; i < 1000; ++i) {
var o = JSON.parse(data);
if (o === undefined) {
console.log("ZOMG");
}
if (doSubKeyTest && o["web-app"]["servlet-mapping"]["fileServlet"] != "/static/*") {
console.log("ERROR");
}
}
console.log("JSON took " + (Date.now() - startTime) + " to run 1000 times");
var startTime = Date.now();
for (var i = 0; i < 1000; ++i) {
var o = cache.parse(data);
if (o === undefined) {
console.log("ZOMG");
}
if (doSubKeyTest && o["web-app"]["servlet-mapping"]["fileServlet"] != "/static/*") {
console.log("ERROR");
}
}
console.log("js0n took " + (Date.now() - startTime) + " to run 1000 times");
/*
var jsonStr = '{"test":"strings", "numVal":1234, "someBool":true, "yuck":null, "subObj":{"subValue":1, "array":[1, 2, 3, 4, 5, 6, 5,5,5,5,5,5,5,5], "lastKey":"wrong"}, "lastKey":"last!"}';
console.log("Json length: " + jsonStr.length);
var o = cache.parse(jsonStr);
function checkKey(key) {
var val = o[key];
console.log("-----------------------------------------------------------------------------------");
console.log(" Key: " + key);
console.log("Value: " + val);
console.log(" Type: " + typeof(val));
console.log("===================================================================================");
}
checkKey("someBool");
checkKey("test");
checkKey("numVal");
checkKey("yuck");
console.log("subValue should be 1: " + o.subObj.subValue);
checkKey("lastKey");
*/