Ticket #228 (new Task: null)
Opened 5 years ago
Replace Python calls to "for i in range(len(x))" to "for i, v in enumerate(x)"
|Reported by:||jjr8||Owned by:||jjr8|
|Component:||Core - Other||Version:|
Currently, there are probably a lot of places where this is done:
for i in range(len(x)): # Do something with i and x[i]
This is normally fine, but if len(x) is large, then the range call can require a lot of memory. This design:
for i, v in enumerate(x): # Do something with i and v
Requires less memory and is nearly as fast. For an array of 20,000,000 integers, the first design required about 7 seconds to process a certain block of code for each integer. The second design required about 7.25 seconds but only used 1/2 of the memory.
I should review the code for the first design and convert them to the second, if memory could be an issue.