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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • maestro

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

    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?
  • Chris

    #2
    Re: if len(str(a)) == len(str(r)) and isMult(a, r): faster if isMultis slow?

    On Aug 11, 3:03 pm, maestro <notnorweg...@y ahoo.sewrote:
    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

    Comment

    Working...