Reputation: 33
I am average at python and not even that at maths.
The equation y = 122.32e-0.31x can be used to calculate how much faster your web page load is compared to other. So a site that loads in 5 seconds is faster than 25% of websites.
Y is the percentage faster and x is the page load in seconds.
This data was found here - http://www.seomoz.org/blog/site-speed-are-you-fast-does-it-matter
To convert this in to python I have tried the following :
import math
# y = 122.32e-0.31x
y = (122.32*math.e)**(-0.31 * page_load_time)
Doesn't seem to be right. Can anyone correct the code?
Upvotes: 0
Views: 150
Reputation: 4114
The equation is y = 122.32e
-0.31x
In python, it will be :
y = 122.32*math.e**(-0.31*x)
I did some time measurements :
>>> t = timeit.Timer('for i in l : e**i', setup = 'from math import e; l = range(10,50)')
>>> t.timeit()
23.76981210708618
>>> t2 = timeit.Timer('for i in l : exp(i)', setup = 'from math import exp; l = range(10,50)')
>>> t2.timeit()
13.754070043563843
>>> t.timeit()
23.382396936416626
>>> t2.timeit()
13.842521905899048
It appears that the implementations of both the methods are different and that math.exp
, as mentioned by @MrDave, is faster than math.e
Upvotes: 2
Reputation: 279
import math
y = 122.32*math.exp(-0.31*page_load_time)
should do what you want
Upvotes: 3