-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
139 lines (130 loc) · 4.56 KB
/
demo.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
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
<html>
<body>
<h1>Test</h1>
<script src="2darray.js"></script>
<script>
var fontsizemultiply = 0.5;
var dimensions = [30, 30];
var numofitems = dimensions[0] * dimensions[1];
var datatext = "";
var methodoptions = ["szudzik", "interleave", "triangle", "primefactor", "cantorpair", "bitwise", "hopullman", "rosenstrong"];
var testerobject = {
interleave: [],
triangle: [],
primefactor: [],
cantorpair: [],
bitwise: [],
szudzik: [],
hopullman: [],
rosenstrong: []
};
var times = {
interleave: 0,
triangle: 0,
primefactor: 0,
cantorpair: 0,
bitwise: 0,
szudzik: 0,
hopullman: 0,
rosenstrong: 0
}
var decodetimes = {
interleave: 0,
triangle: 0,
primefactor: 0,
cantorpair: 0,
bitwise: 0,
szudzik: 0,
hopullman: 0,
rosenstrong: 0
}
var repeats = {
interleave: 0,
triangle: 0,
primefactor: 0,
cantorpair: 0,
bitwise: 0,
szudzik: 0,
hopullman: 0,
rosenstrong: 0
}
var fails = {
interleave: 0,
triangle: 0,
primefactor: 0,
cantorpair: 0,
bitwise: 0,
szudzik: 0,
hopullman: 0,
rosenstrong: 0
}
document.write("<br><br>");
for (var x = 0; x < dimensions[0]; x++) {
for (var y = 0; y < dimensions[1]; y++) {
methodoptions.forEach(function(item) {
var t0 = performance.now();
var indexarray = tdarrayindex.encode(x, y, item);
var t1 = performance.now();
var t2 = performance.now();
var output = tdarrayindex.decode(indexarray, item, false, false);
var t3 = performance.now();
times[item] += t1 - t0;
decodetimes[item] += t3 - t2;
var failtext = "";
var text;
if (!output) {
text = " -> No decoding func";
} else if (output[0] !== x || output[1] !== y) {
fails[item]++;
text = " -> (" + output[0] + ", " + output[1] + ") FAIL";
} else {
text = " -> (" + output[0] + ", " + output[1] + ") PASS";
}
datatext += "(" + x + ", " + y + "): " + item + " -> " + indexarray + text + "<br>";
if (testerobject[item][indexarray]) {
repeats[item]++;
}
testerobject[item][indexarray] = "whatever.";
});
datatext += "<br>";
}
}
if (document.body.style.fontSize == "") {
document.body.style.fontSize = "1.0em";
}
document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (fontsizemultiply * 0.2) + "em";
document.write("dimensions: " + dimensions[0] + " by " + dimensions[1] + " units");
document.write("<br><br>");
document.write("Efficiencies (percentage of values assigned in first x * y indices of array; x * y is the amount of indices that were registered and the dimension of the x and y value block; the lower this value is, the less spread out the array will be):");
methodoptions.forEach(function(item) {
var counter = 0;
for (var d = 0; d < numofitems; d++) {
if (testerobject[item][d]) {
counter++;
}
}
document.write("<br>" + item + ": " + (counter / numofitems) * 100 + "%");
});
document.write("<br><br>Encode performance:");
methodoptions.forEach(function(item) {
document.write("<br>" + item + ": " + (times[item] / numofitems) * 1000 + " microseconds");
});
document.write("<br><br>Decode performance:");
methodoptions.forEach(function(item) {
document.write("<br>" + item + ": " + (decodetimes[item] / numofitems) * 1000 + " microseconds");
});
document.write("<br><br>Repeat percentage (percentage of times a index was set more than once):");
methodoptions.forEach(function(item) {
document.write("<br>" + item + ": " + (repeats[item] / numofitems) * 100 + "%");
});
document.write("<br><br>Fail percentage (percentage of times a decode did not match the values that were decoded):");
methodoptions.forEach(function(item) {
document.write("<br>" + item + ": " + (fails[item] / numofitems) * 100 + "%");
});
document.write("<br><br><button onclick='writedata();'>Click for raw data</button>");
function writedata() {
document.write(datatext);
}
</script>
</body>
</html>