user13527546
user13527546

Reputation:

Cython - What Makes My Program Slow and How to Speed It Up?

I am trying to speed up my cython program but I get an error on everything that I add. Does anyone know what can I do?

Here is the code:

cpdef char breaker(str a): 
       cdef list strings = list("abcčćdđefghijklmnoprsštuvzžqwxy1234567890ABCČĆDĐEFGHIJKLMNOPRSŠTUVZŽQWXY")
       cdef int i
       cdef int b = 0
       cdef str string1, string2, string3, string4, string5, string6, string7, string8
       cdef str password
       for i in range(len(strings)):
              string1 = strings[i]
              for i in range(len(strings)):
                     string2 = strings[i]
                     for i in range(len(strings)):
                            string3 = strings[i]
                            for i in range(len(strings)):
                                   string4 = strings[i]
                                   for i in range(len(strings)):
                                          string5 = strings[i]
                                          for i in range(len(strings)):
                                                 string6 = strings[i]
                                                 for i in range(len(strings)):
                                                        string7 = strings[i]
                                                        for i in range(len(strings)):
                                                               string8 = strings[i]
                                                               output = string1 + string2 +string3 + string4 + string5 + string6 + string7 + string8
                                                               if a == output:
                                                                      password = output
                                                                      quit()

                                                               if b >= 100000:
                                                                      b = 0
                                                                      print(output)

                                                               else:
                                                                      b += 1


       return password

print(output) is not neccessary line, please let me know if that can slow down the program. Here is the image of html file that shows what parts of the program are slower(yellow lines) and what are faster(white lines):

https://i.sstatic.net/dLn88.png

I am new to cython and this program is just test for future bigger projects. Thanks in advenced!

Upvotes: 0

Views: 107

Answers (1)

visibleman
visibleman

Reputation: 3315

You are brute forcing 72^8 = 722204136308736 password combinations. It is bound to take its sweet little time.

(Also please don't use the same iterator "i" for all your nested loops)

Upvotes: 1

Related Questions