-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice.js
96 lines (76 loc) · 2.12 KB
/
slice.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
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
(function() {
// Generated by CoffeeScript 1.10.0
const memwatch = require('memwatch-next');
const heapdump = require('heapdump');
memwatch.on('leak', (info) => {
console.error('Memory leak detected:\n', info);
heapdump.writeSnapshot((err, filename) => {
if (err) console.error(err);
else console.error('Wrote snapshot: ' + filename);
})
});
memwatch.on('stats', function(stats) {console.info("Memory stats:\n ", stats)});
var ALPHABET, N, SMALL_STRINGS, getSlice, largeString, nextTick, processParts, randomString;
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (typeof window === "undefined" || window === null) {
nextTick = setImmediate;
} else {
nextTick = window.nextTick;
}
randomString = function(len) {
var a, i;
a = (function() {
var j, ref, results;
results = [];
for (i = j = 0, ref = len; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
results.push(ALPHABET[parseInt(Math.random() * 26)]);
}
return results;
})();
return a.join('');
};
largeString = function() {
var a, i, j, s1, s2;
s1 = randomString(10000);
s2 = randomString(10000);
a = [];
for (i = j = 0; j < 500; i = ++j) {
a.push(s1);
a.push(s2);
}
return a.join('');
};
SMALL_STRINGS = [];
if (typeof window !== "undefined" && window !== null) {
window.SMALL_STRINGS = SMALL_STRINGS;
}
N = 0;
getSlice = function(large) {
var n, s;
n = Math.random() * (large.length - 500);
s = large.substr(n, 500);
return SMALL_STRINGS.push(s);
};
write = function (){
heapdump.writeSnapshot((err, filename) => {
if (err) console.error(err);
else console.error('Wrote snapshot: ' + filename);
});
};
processParts = function() {
var i, j, large;
large = largeString();
for (i = j = 0; j < 10; i = ++j) {
getSlice(large);
}
N++;
if(N === 144){
console.info("I am writing");
write();
}
console.log("cycles: " + N + ", strings: " + SMALL_STRINGS.length);
//return nextTick(processParts);
processParts();
};
processParts();
}).call(this);