dimanche 29 janvier 2017

Most efficient if statement?

I would like to write a function that takes integer numbers x, y, L and R as parameters and returns True if x**y lies in the interval (L, R] and False otherwise.

I am considering several ways to write a conditional statement inside this function:

  1. if L < x ** y <= R:
  2. if x ** y > L and x ** y <= R:
  3. if x ** y in range(L + 1, R + 1):

Why is option 1 the most efficient in terms of execution time ?

Aucun commentaire:

Enregistrer un commentaire