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:
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.
use arraylist instead of byte-array , overwrite "get" method. again, there lot of methods have modified , suspect there performance loss.
can somehow use eclipse debug-mode? see can specify hit-count watchpoints not seem possible output hit count?!
can maybe reflection api me somehow?
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
Post a Comment