I am creating a graphing program which has to iterate values through a calculation 10000-1000000 times, and then append part of that output to a list. In order to change which list it is appended to, there are ~3 if statements inside that loop. While it would logically be faster to use the if statement first, is there a significant amount of time saved?
As an example:
output = []
append_to = "pol"
for i in range(10000):
if append_to == "pol":
output.append(np.cos(i))
else:
output.append(np.sin(i))
Would this be significantly slower than:
output = []
append_to = "pol"
if append_to == "pol":
for i in range(10000):
output.append(np.cos(i))
else:
for i in range(10000):
output.append(np.sin(i))
append_tomay change, otherwise the whole question has no point)append_tostay the same during the entire loop? In that case, you could definef = np.cos if append_to == "pol" else np.sinand then dooutput = list(map(f, range(10000))