I have a program with a while loop that is running really slowly. I'm making a program that finds how many tries it takes to reach a certain password but it takes about five minutes to get to the fourth character in the string and I'm hoping to get to around 18 characters.
Well, you can't expect much speed if you print a line in every iteration of the loop, so you should remove that.
Aside from that, I have no idea what the code is supposed to do, except that it can be improved significantly (that probably applies to execution speed as well). You should not use magic numbers (126, 32) or non-descriptive variable names (L, G).
Aside from that, are you compiling with -O3? -march=native can also help if the program is not supposed to run on other machines.
I'm programming with Dev-C++. I used 32 and 126 to narrow down the characters to ones that you can find on an English keyboard. The program in general is to type in a word and it tells you how many tries it takes to get the word. I chose simple variables to make it easier to remember instead of longer ones to keep track of. I was wondering if there was any way to make the while loop execute at a faster rate.
Sorry. I think I see what you mean by removing the lines but I'm not quite sure what you mean by that. Could you please explain just that part. I get the rest.
Move your cursor to somewhere in that line: cout << endl << time << " tries Password: " << tries << endl;
Then press End, Shift+Home, Backspace, Backspace.
I used 32 and 126 to narrow down the characters to ones that you can find on an English keyboard.
If you mean characters, you should use ' ' and '~'.
I chose simple variables to make it easier to remember instead of longer ones to keep track of.
Using non-obvious and non-descriptive variable names will just make it easier to remember when you look at the code later.
Just don't do it.
often, the slowest part of a program is I/O - that means to/from the screen, disk, socket, etc... so the more often you do it, the slower your program will run - writing to cout counts
when possible, you want to chunk I/O together and call them less often
The variables are actually characters in my passwords. I chose them so I could eventually apply my password to the program and find out how secure it is. The variables hold the key to it which is why I chose them