0
Basically the program I did does this same procedure, but with more data. I need to increase search performance, of course this can be done with libraries if it’s better. No matter how you improve performance, as long as the data format remains.
import time
import random
numbers = []
searchs = []
search_range = 1
for i in range(0, 9999):
numbers.append((int(random.random() * 100), int(random.random() * 100), int(random.random() * 100)))
searchs.append((int(random.random() * 100), int(random.random() * 100), int(random.random() * 100)))
start = time.time()
for search in searchs:
for number in numbers:
if (search[0] > (number[0] - search_range) and search[0] < (number[0] + search_range) and
search[1] > (number[1] - search_range) and search[1] < (number[1] + search_range) and
search[2] > (number[2] - search_range) and search[2] < (number[2] + search_range)):
print(number)
break
print('Time: %.2f' % (time.time() - start))
Note: Remembering that only what I want is the performance of the search, the rest of the program was just an example.
It doesn’t solve the problem, but makes the code more pythonic: https://repl.it/repls/ClosedNormalMarmot, as far as comparisons/ranges are concerned, you can also use
randint
and you don’t need to make it whole– Miguel
@Miguel I didn’t know that I could do it this way, I’m going to correct it. And you know some library that I search this way but with more performance ??
– Lucas Caresia
You will always have to compare each value of one list with each value of the other. That way I was able to reduce 2-3secs, it’s not relevant but it reduces a little
– Miguel
@Miguel I thought I was going to have a library for this kind of processing.
– Lucas Caresia
One more optimization: https://repl.it/repls/ClosedNormalMarmot . By avoiding internal print, and using a generator
– Miguel