3

for example i want to compare about "array of array of number" with "array of string" to store bits of static canvas/image that has Alpha more or less than 0.5, that i will need to read/access it later

i wonder which one would have least memory usage and probably faster?

var c =$('$myCanvas');
var d = c[0].getContext('2d').getImageData().data; 
// access: d[3+4*(c.width()*y+x)] >= 0.5

vs

var n = [ [ 2147483647, 2147483647, 2147483647 ], [ 0, 0, 0 ], ... ]
// access: n[y][x/31|0] >> x%31 & 1

vs

var s = [ [ 255, 255, 255, 255, ... ].to_s(), [ 0, 0, 0, 0, ...].to_s(), ... ]
// access: n[y].charCodeAt(x/8|0) >> x%8 & 1    

note that to_s() is custom function to convert array of byte to string similar to this one: https://codereview.stackexchange.com/questions/3569/pack-and-unpack-bytes-to-strings

those codes are probably wrong, it's just the concept that i will implement later

so, my question is, how to measure memory usage of d, n and s?

Community
  • 1
  • 1
Kokizzu
  • 24,974
  • 37
  • 137
  • 233

1 Answers1

1

You can consider the V8 profiler. Playing with it's flags you can get the heap usage. Probably that's what you need.

Minko Gechev
  • 25,304
  • 9
  • 61
  • 68