Consider the following snippet.
for (int i = targetIndex; i < totalInTarget; i++) {
++step;
_KVPair kvp = target.get(i);
if (previousKey == null) {
++step;
currentKey = kvp.getKey();
...
Is there a way for me to know number of instructions taken:
- Each iteration
- Each if/else decision
Without manually counting them with ++step;
Short answer, no.
You could use javap to show you the bytecode, but that doesn’t translate directly to CPU instructions (if that’s what you mean). The number of instructions will vary on whether it’s interpreted or JIT’ed, how it’s optimized and possibly other factors (GC options?).