forked from pubnub/pubnub-rickshaw-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
46 lines (32 loc) · 909 Bytes
/
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
var pnrickmem = require('./app');
pnrickmem.init({
dev: true
});
console.log('- starting encryption loop to illustrate memory deviation');
// a super slow function
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
// increase memory usage artificially
setInterval(function(){
console.log('-- encrypting');
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = makeid();
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
var i=0;
while(i < 10000) {
encrypt(makeid());
i++;
}
console.log('-- sleep');
}, 5000);