0

I am making a program in Java for a school project that involves you inputting a word, and then the program will loop through most characters to try and eventually match the word.

This is the character list: eaorinsltmdcybhgufEAORINSL1T2MDCY0BHGU3F$%^*!#KkPpWwZzJjQqVvXx456789@&()~`-=_+[]{}\|;:\'\"/?.>,<

Basically, my program will start at 6 characters, which will be "eeeeee" (because that is the first letter in the list). The last letter loops through each of the characters in that list, and then the second to last moves up one and the last character loops through all the characters again, and so on. (For example: eeeeee > eeeeea > eeeeeo > eeeeer etc. Then it becomes eeeeae > eeeeaa > eeeeao etc. And it moves on and finally ends at "<<<<<<", because that is the last character).

After the search of 6 letters is done, and if the word was not matched, the program moves to 7 letters (eeeeeee) and does the same thing. It does all its loops and continues to add letters until the word is matched.

As you can tell, this is VERY VERY VERY time consuming in my program, especially when matching words like "StrusHMAnGEnDiAt." (its a project on passwords and how fast it takes for a program to match a fake password provided).

Instead of waiting for my program to do the loop, how could I find the time it will take (in hours, minutes, seconds) for a for-loop to do all this?

Blockhead7360
  • 145
  • 10
  • 1
    You cannot measure the execution time of a program without executing it. Time will vary from system to system. During execution, you can use `System.nanoTime()` to calculate how long it takes your program to execute. – kkmonlee Jan 10 '17 at 07:35
  • Measure the time it takes to run N loops (say N=10 million) - calculate how many loops are required (simple maths exercise) and derive the time it will take. Note that the first step is very sensitive to how you measure the time - if you want to do it properly, you should probably use jmh - a good read: http://stackoverflow.com/questions/504103/how-do-i-write-a-correct-micro-benchmark-in-java – assylias Jan 10 '17 at 09:07

0 Answers0