Hit-Count (reads) of an array in Java -


for evaluating algorithm have count how items of byte-array read/accessed. byte-array filled contents of file , algorithm can skip on many of bytes in array (like example boyer–moore string search algorithm). have find out how item read. byte-array passed around multiple methods , classes.

my ideas far:

  1. increment counter @ each spot byte-array read. seems error-prone since there many of these spots. additionally have remove code afterwards such not influence runtime of algorithm.

  2. use arraylist instead of byte-array , overwrite "get" method. again, there lot of methods have modified , suspect there performance loss.

  3. can somehow use eclipse debug-mode? see can specify hit-count watchpoints not seem possible output hit count?!

  4. can maybe reflection api me somehow?

  5. somewhat 2), in order reduce effort: can make java method accept arraylist wants array such transparently calls "get" method whenever item read?

there might out-of-the-box solution i'd wrap byte array in simple class.

public class bytearraywrapper {   private byte [] bytes;   private long readcount = 0;    public bytearraywrapper( byte [] bytes ) {     this.bytes = bytes;   }    public int getsize() { return bytes.length; }    public byte getbyte( int index ) { readcount++; return bytes[ index ]; }    public long getreadcount() { return readcount; } } 

something along these lines. of course influence running time not much. try , time difference, if find significant, we'll have find way.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -