OH my god this is so slow

Code: Select all

```
from frange import frange
log=[]
for a in frange(0,100,0.1):
for b in frange(0,100,0.1):
for c in frange(0,100,0.1):
for d in frange(0,100,0.1):
if a<=12 and b<=5 and c<=25 and d<=20 and c+d>=5:
if 800*a+925*b+290*c+380*d <= 8000:
log.append(5000*a+8500*b+2400*c+2800*d)
print "-"
print max(log)
```

Two things make this go faster. 1) If I loose the frange() function and use range() it goes a LITTLE faster, but still at a snails pace.

2) If I DON'T use python and use the pypy interpreter it goes a super fast! But it goes back to slow when I use frange()... GRRR!!!

However, even using pypy this becomes just as slow...

Code: Select all

```
log=[]
for a in range(0,1000,1):
a=a*0.1
for b in range(0,1000,1):
b=b*0.1
for c in range(0,1000,1):
c=c*0.1
for d in range(0,1000,1):
d=d*0.1
if a<=12 and b<=5 and c<=25 and d<=20 and c+d>=5:
if 800*a+925*b+290*c+380*d <= 8000:
log.append(5000*a+8500*b+2400*c+2800*d)
print ("-")
print (max(log))
```

Conclusion:

I'm guessing there's complicated way to do this faster, but I think I've hit the limit, for the first time, on python's, and its variants, speed.

For now I'll be using c based user friendly python libraries for Linear Programming, which seem to be abundant. Sort of disappointed that such a simple loop would cost so much, but that's learning.