-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.html
107 lines (102 loc) · 3.6 KB
/
test.html
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
<!doctype html>
<html>
<head>
<title>JSON Zipper</title>
<meta http-equiv="Cache-Control" content="no-store" />
<script>
var exratio = function(startL,endL) {
return ((endL/startL * 100) - 100) + ' % ::: from '+startL+' to '+endL;
};
var ratio = function(startL,endL) {
return ((startL/endL * 100) - 100) + ' % ::: from '+startL+' to '+endL;
};
var sT = performance.now();
/* Which index range in the array to extract after compressing */
var startIndex = 169;
var endIndex = 169;
</script>
<script src="testFile.js"></script>
<script src="jsonZipper.js"></script>
<style type="text/css">
textarea {
width: 900px;
height: 100px;
}
</style>
</head>
<body>
<textarea id="jsonZipper">jsonZipper...</textarea>
<p id="total">Testing...</p>
<script type="text/javascript">
/* A anonymous function used to generate a new value for each object */
var first = false;
var msTime = function(j) {
if (j) {
if (first) {
return new Date(j.timestamp) - first;
} else
first = new Date(j.timestamp);
}
return 0;
};
/*
Create the jsonZipper object to compress as a stream, with options.
To compress entire object, just replace false with jsonObj (your object array)
*/
var jZ = new jsonZipper(false/* or jsonObj */,{identifiers:["type","selector"]/*,exclude:["ti"]*/,include:["isRelative","targetWidth","targetHeight"]/*,remove:["timestamp"],add:{ti:msTime}*/});
/*
For stats
*/
var startLength = JSON.stringify(jsonObj).length;
var i = 0;
var arrLength = jsonObj.length;
/*
Start the zipping process as a stream, taking time for first object
Note: could also just use jZ.zip(); to zip entire object.
*/
var fS = performance.now();
var zippedObj = jZ.compress(jsonObj[i++]);
var fE = performance.now();
/* Continue with rest of objects */
var start = performance.now();
while (i<arrLength)
zippedObj = jZ.compress(jsonObj[i++]);
var end = performance.now();
/*
Output the compression statistics
*/
var endLength = jZ.length();
document.getElementById('jsonZipper').innerHTML += "\nZipping first object took "+(fE-fS)+"ms";
document.getElementById('jsonZipper').innerHTML += "\nZipping took "+((end-start)+(fE-fS))+"ms, with a compression ratio of "+ratio(startLength,endLength);
/*
Load the zipped object, for extracting test
Set counter for index range
*/
jZ.load(zippedObj,true);
i = startIndex;
var extractObj = [];
//extractObj = jZ.unzip(); /* Optional way to extract everything */
/* Stats for extracting just one object */
startLength = endLength;
fS = performance.now();
extractObj.push(jZ.extract(i++));
fE = performance.now();
start = performance.now();
while (i<endIndex) {
extractObj.push(jZ.extract(i++));
}
end = performance.now();
endLength = jZ.length();
/*
Output the extraction statistics
*/
sL = jZ.length();
document.getElementById('jsonZipper').innerHTML += "\nGetting first object @ index "+startIndex+" took: "+(fE-fS)+"ms";
document.getElementById('jsonZipper').innerHTML += "\nGetting objects from "+startIndex+" to "+endIndex+" took: "+((end-start)+(fE-fS))+"ms, with a extraction ratio of "+exratio(startLength,endLength);
//document.getElementById('jsonZipper').innerHTML += "\nGetting all objects from took: "+(end-start)+"ms, with a extraction ratio of "+exratio(eL,sL);
/* Total test stats */
var eT = performance.now();
document.getElementById('total').innerHTML = "Total test used "+(eT-sT)+"ms to complete";
</script>
</body>
</html>