summaryrefslogtreecommitdiff
path: root/node_modules/webworker-threads/test/test04_gc_versus_not_gc.js
blob: af745ebd092cfd9491e42df3a2b9d626c2ef847f (plain)
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
var Threads= require('webworker-threads');

console.log('Launch with/without --expose_gc to compare memory usage')

function cb (err, msg) {
  i++;
  if (msg) console.log('['+ this.id+ ']'+ msg);
  this.eval(source, cb);
  //process.stdout.write('['+ this.id+ ']['+ i+ '] -> '+ msg+ '\n');
  //process.stdout.write('['+ this.id+ ']');
}


function ƒ () {
  if (++i % 10e3) return '';
  try {
    gc();
    return ' -> gc()'
  }
  catch (e) {
    return ' -> *NOT* gc()]';
  }
}
var source= "ƒ()";

var i= +process.argv[2] || 1;
console.log('Using '+ i+ ' threads');


while (i--) {
  Threads.create().eval(ƒ+ '\nvar i= 0;').eval(source, cb);
}

i= 0;
var t= Date.now();
function display () {
  var e= Date.now()- t;
  var tps= (i*1e3/e).toFixed(1);
  console.log('t (ms) -> '+ e+ ', i -> '+ i+ ', tps -> '+ tps);
}

setInterval(display, 1e3);