-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
93 lines (86 loc) · 2.88 KB
/
index.html
File metadata and controls
93 lines (86 loc) · 2.88 KB
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
<!doctype html>
<html>
<head>
<title>radix64 demonstration</title>
<style>
label { width: 200px; float: left; clear: both }
label input { float: right; width: 100px }
button { float: left; margin-left: 10px }
label input, button { position: relative; bottom: 5px }
input[readonly] { border-color: transparent }
#width { width: 50px }
br { clear: both }
</style>
<script src="radix64.js"></script>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(function() {
$(':input[type=number]').change(function() {
var v = parseFloat(this.value);
var min = parseFloat(this.min);
var max = parseFloat(this.max);
var step = parseFloat(this.step);
if(v < min) v = min;
else if (v > max) v = max;
else v = Math.floor((v - min) / step) * step + min;
this.value = v;
});
$('#encoded').change(function() {
this.value = this.value.replace(/[^0-9A-Za-z_-]+/, '');
});
$('#decoded').val(Math.round(Math.random() * 65535));
$('#encode').click(function() {
$('#encoded').val(enc64($('#decoded').val(), $('#width').val()));
}).click();
$('#decode').click(function() {
$('#decoded').val(dec64($('#encoded').val()));
});
var bench = function(config, func) {
$('#benchresult').val("processing...");
var iters = parseInt($('#iterations').val());
var start = new Date();
var len = func(config, iters);
var duration = (new Date() - start) * 1e6;
var op = Math.round(duration / iters);
var ch = Math.round(op / len);
$('#benchresult').text(op + " ns/op; " + ch + " ns per encoded digit");
};
$('#benchenc').click(function() {
bench({
v: parseInt($('#decoded').val()),
w: parseInt($('#width').val())
}, function(config, iters) {
var v = config.v, w = config.w;
for(var i = 0; i < iters; i++)
enc64(v, w);
return enc64(v, w).length;
});
});
$('#benchdec').click(function() {
bench({
v: $('#encoded').val(),
}, function(config, iters) {
var v = config.v;
for(var i = 0; i < iters; i++)
dec64(v);
return v.length;
});
});
});
</script>
</head>
<body>
<fieldset><legend>Values</legend>
<label>Decoded: <input id=decoded type=number min=0 step=1 /></label><button id="encode">Encode</button><br />
<label>Width: <input id=width type=number min=0 max=10 step=1 value=0 /></label><br />
<label>Encoded: <input id=encoded /></label><button id="decode">Decode</button><br />
</fieldset>
<fieldset><legend>Benchmark</legend>
<p>(Benchmarking will use the above encode/decode values)</p>
<label>Iterations: <input id=iterations type=number min=1 step=1 value=100000 /></label>
<button id="benchenc">Encode</button>
<button id="benchdec">Decode</button><br />
Result: <span id=benchresult>n/a</span>
</fieldset>
</body>
</html>