I'm currently solving a combinatorics problem which I have boiled down to a smaller, more manageable task of studying the asymptotic behavior of the problem. The code has more depth to it than what I've shared but the following blocks target my question.
I'm currently testing my code with ~1E7
iterations but the final product will need to loop through ~1E11
iterations. In the following code examples, <condition_1>
is used to reduce the search space down to a sufficient set of size << ~1E7
. A partial computation of one of the results I need is used to see if it satisfies an inequality; since I only need to store key-value pairs which satisfy the inequality, I use <condition_2>
to decrease the load on memory.
I had implemented two versions of my code. I am currently using Way 2 in hopes of being more performant. For my general knowledge: Will python 'lazily' evaluate the conditional, ie. if the first condition is false -- not compute the second condition?
# Way 1
for i in range(N):
<computation related to condition_2, used in code block>
if <condition_1> & <condition_2>
<code block>
<storing results in dictionary>
# Way 2
for i in range(N):
if <condition_1>:
<computation related to condition_2, used in code block>
if <condition_2>:
<code block>
<storing results in dictionary>