RE: 2.5 feature for speed?
- Posted by Matt Lewis <matthewwalkerlewis at yahoo.com> Jan 26, 2004
- 419 views
> From: Euman > > > Im sorry, I get 4.12 seconds for euphoria for win > and 15.2 on euphoria for dos > > > > > Rob see if you can optimize this in the next version PowerBasic > > Elapsed time: 0.84 seconds on a 600 Mhz Pentium, this takes 15.2 > > seconds on my 2.53ghz using Euphoria > > > > simple floating point operation > > > > without type_check > > > > atom t, x, y > > x = 1 > > y = 1.000001 > > t = time() > > for i = 1 to 100000000 do > > x *= y > > end for What exactly are you interested in optimizing? I suspect that it's not this *exact* case, since you could be a lot faster with power(). You're probably more interested in floating point arithmetic in general. Perhaps it would be beneficial to have a float sub-datatype of atom like we have integers (although I think this might break a lot of stuff inside the interpreter). You could get rid of some of the overhead of checking for floating points the same way you do with using pure integers. Here's a function that can calculate large powers pretty quickly: function power_big( atom num, atom pow ) sequence bits, p2 integer bit, last, ix atom t, result, powers bit = 1 p2 = {} bits = int_to_bits( pow, 32 ) for j = 1 to 32 do if bits[j] then p2 &= bit end if bit += 1 end for last = length(p2) powers = num if find(1,p2) then result = num ix = 2 else result = 1.0 ix = 1 end if bit = 1 while ix <= last do powers *= powers bit += 1 if p2[ix] = bit then result *= powers ix += 1 end if end while return result end function Here are some benchmarks from a 2.4GHz P4. power(): 26879827172956060000000000000000000000000000 (0.0000003137s) power_big:26879827232954420000000000000000000000000000 (0.0000056s) bigbase: 26879827394087344246158930004723131138766976 (0.0115s) euman: 26879827172977660000000000000000000000000000 (3.610000s) bigbase is a bigmath library that I've worked on now and then, and I've only given the integer part (power_big was based on bigbase.e code). The calculation was done using 3000 bits of accuracy (there are 148 digits beyond the decimal point). The integer part is stable even if I increase to 30,000 bits, so you can see that we're only getting about 8 of 16 digits accurately. I translated your code and compiled with OpenWatcom 1.0 (euman1). Then I optimized the loop a bit for euman2 by avoiding creating a new double each time, and it ran a lot faster: euman1: 26879827172977660000000000000000000000000000 (3.966000s) euman2: 26879827172977660000000000000000000000000000 (1.191000s) The new loop: if (_0i > 100000000) goto L3; //_0 = _0x; //_0x = NewDouble(DBL_PTR(_0x)->dbl * DBL_PTR(_0y)->dbl); //DeRef(_0); DBL_PTR(_0x)->dbl = DBL_PTR(_0x)->dbl * DBL_PTR(_0y)->dbl; _0i = _0i + 1; goto L2; I suspect that this is the sort of optimization that we can expect for Rob to start making in the new Euphoria-coded translator. Matt Lewis