if len(str(a)) == len(str(r)) and isMult(a, r): faster if isMult isslow?

M

maestro

If isMult is slow then:

if len(str(a)) == len(str(r)) and isMult(a, r):
trues.append((a, r))

will be much faster than:

if isMult(a, r) and len(str(a)) == len(str(r)):
trues.append((a, r))

right? seems obvious but there is no magic going on that wouldn't
make this true right?
 
C

Chris

If isMult is slow then:

if len(str(a)) == len(str(r)) and isMult(a, r):
                trues.append((a, r))

will be much faster than:

if isMult(a, r) and len(str(a)) == len(str(r)):
                trues.append((a, r))

right? seems obvious  but there is no magic going on that wouldn't
make this true right?

Once a failed condition is met the rest are skipped for evaluation.
Whether or not that saves you any reasonable amount of time would be
up to the various tests being used with your conditions.

If your function isMult is just doing the same work as "if not a % r"
then that would be faster than casting your integers/floats to a
string and testing their length imo.

You could always go through the trouble of profiling your code with
separate if statements to see how much time is spent on each, also
note your mean failure rate for each conditional test and then decide
for yourself which to place first.

Hope that helps,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top