I've been looking to optimize my code because it's not working as fast as I would like it to and I've found something weird. I tried to use a profiler to pinpoint the slow parts of my code but with visualvm in Eclipse I get internal errors so it doesn't run. Instead I just print out a bunch of System.nanoTime()'s to console, paste that into a text file and have a separate java program read them in and show me the slow parts. Not elegant I know but it works.
So here's a code snippet to show the problem where ty and tx are both ints between 0 and 15 inclusive, and cellMap is a 16x16 int array within that object.
This is a typical output from this
ty 1367974976386656000TIME startswitch 1367974976386676000
so it only takes 20,000 nanoseconds which is fine.
This is a ridiculous output from this
ty 1367974977431169000TIME startswitch 1367974977468862000
this version takes 37,693,000 nanoseconds... for just that code snippet...
This isn't an isolated case, every time I run this program there's at least one ridiculous result but it moves around and in consecutive runs, usually won't be in the same spot.
I do have two threads running but I doubt it would swap away from a thread for that long at a time would it? I used two threads to try and get them going simultaneously instead of swapping from one to the other, have I done something wrong here?
How can I further diagnose what's going on?
Any help would be greatly appreciated, thanks.