Well, last night before I went to sleep I was programming the majority of that day working on a program that would:
A: Record the users screen every 21 - 33.3 milliseconds.
B: After recording, store the captured frames, than start a GUI that will shuffle through the pictures giving a feeling of smooth motion. (play/pause buttons etc)
My problem while programming is that half the time while I’m programming a project, after I’ve turned it into something nice/useable, I’ve as some might call it ‘hard-coded’ it, figured out where it starts/stops etc programmed the program to run smoothly if that makes sense o.O.
Here is my question: Why is example 2 taking 3 seconds+ to complete 1 loop, where in example 1 it executes 1 loop in about 0-16ms?
The only difference between the two examples, it that example 2 calls ‘System.out.println’ before starting the loop.
Example 1:
public Launcher() {
int loops= 0;
elapsed = System.currentTimeMillis();
while(!destroyed){
if (loops < 2147000000) {
loops++;
} else {
System.out.println("[BreakPoint @ "+loops+" loops, finished in: "+(System.currentTimeMillis() - elapsed)+"ms]");
destroyed = true;
}
}
System.out.println("[BreakPoint: After While Statement]");
}
Example 1 returns:
[BreakPoint @ 2147000000 loops, finished in: 0ms]
[BreakPoint: After While Statement]
Example 2:
public Launcher() {
int loops= 0;
System.out.println("[StartPoint @ "+loops+" loops]");
elapsed = System.currentTimeMillis();
while(!destroyed){
if (loops < 2147000000) {
loops++;
} else {
System.out.println("[BreakPoint @ "+loops+" loops, finished in: "+(System.currentTimeMillis() - elapsed)+"ms]");
destroyed = true;
}
}
System.out.println("[BreakPoint: After While Statement]");
}
Example 2 Returns:
[StartPoint @ 0 loops]
[BreakPoint @ 2147000000 loops, finished in: 2996ms]
[BreakPoint: After While Statement]
Hope somebody has some feedback/input, going to be depending on consistency ^__^.
EDIT: I never knew this, I removed the Integer variable ‘loops’ out of the Constructor, and added it’s decleration in the main class as a variable instead, just by doing that it caused the interval rate of which the loop performs at to hop from 0-16ms to 152-172ms?
Nothing’s different, just where the variable was declared D: