-
Notifications
You must be signed in to change notification settings - Fork 4
/
fast-slow.js
61 lines (50 loc) · 1.29 KB
/
fast-slow.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
59
60
61
var Base64 = require('./index.js');
var crypto = require('crypto');
var data = crypto.randomBytes(32 * 1024 * 1024);
var base64 = data.toString('base64');
var base64Buffer = Buffer.from(base64, 'ascii');
var now = 0;
console.log('');
console.log(' Decoding Base64:');
console.log('');
var times = 3;
while (times--) {
now = Date.now();
Buffer.from(base64, 'base64');
console.log(' Node: Decode: ' + (Date.now() - now) + 'ms');
}
console.log('');
var times = 3;
while (times--) {
now = Date.now();
Base64.decode(base64Buffer);
console.log(' Base64: Decode: ' + (Date.now() - now) + 'ms');
}
console.log('');
console.log(' Decoding Base64 (wrapped every 76 characters):');
console.log('');
function wrap(string) {
var lines = [];
var index = 0;
var length = string.length;
while (index < length) {
lines.push(string.slice(index, index += 76));
}
return lines.join('\r\n');
}
base64 = wrap(base64);
base64Buffer = Buffer.from(base64, 'ascii');
var times = 3;
while (times--) {
now = Date.now();
Buffer.from(base64, 'base64');
console.log(' Node: Decode: ' + (Date.now() - now) + 'ms');
}
console.log('');
var times = 3;
while (times--) {
now = Date.now();
Base64.decode(base64Buffer);
console.log(' Base64: Decode: ' + (Date.now() - now) + 'ms');
}
console.log('');