Hi,
Since these kind of lines may appear in mass, such optimization
may result in code size reduction and speed increase.
> Some more optimization ideas from the past: SUBSTR(), ASC( SUBSTR() ),
> RETURN .T., RETURN .F., RETURN NIL
This is easy to do, but I guess it would increase speed very little in
real life app.
Sometimes I return in my mind to more general solutions, like changing
compiler to generate expression tree instead of code, typed variables, etc.
The last nice source of ideas I found is Lua virtual machine. In Lua
5.0, VM was rewritten from stack based machine to register-based
machine. This increased performance about 20%. Instead of:
PUSHLOCAL 1
PUSHLOCAL 2
ADD
POPLOCAL 3
they use:
ADD 3 1 2
Here is some old table with one more Lua column:
No Test code Harbour PHP Python Ruby Java Java+JIT Lua
-----------------------------+------+------+------+------+-------+------+
10'000'000 times:
11 nJ+=nI*2+17 4.61 3.41 6.54 25.53 1.36 0.08 0.63
12 nJ+=17+1+...+1+nI*2 4.61 6.10 6.62 45.86 1.36 0.08 1.63
13 nJ+=nI*2+17+1+...+1 4.62 5.95 12.96 45.78 1.92 0.17 1.56
200'000 times:
21 cI:=cI+"a" 0.08 6.70 0.11 25.80 1641.766 1650.437 23.50
22 cI+="a" 0.08 0.07 0.12 25.83 1649.344 1654.735 -
31 AADD(aI,{nI}) 0.18 0.29 0.32 0.20 0.76 0.40 0.16
32 AADD(aI,{aI[nI-1... 0.25 0.34 0.38 0.39 0.92 0.40 0.18
-------------------------------------------------------------------------
11 Mem Usage (KB) 2680 4296 162400 3244 6684 6892 1464
Instruction count 180 150 143 105 202 35
Lua is very fast on numeric operations. A few differences to Harbour
here are: all numeric are double (no integers); no widths and decimals
are stored for numeric value. This saves some time for overflow check,
integer <-> double conversion, result format. Lua has only 35
instructions! In Lua all arrays are assocciative arrays and they have a
good performance for it also.
http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/jucs05.pdf
http://www.inf.puc-rio.br/~roberto/talks/lua-ll3.pdf
Nice, I didn't know it. But, since -gc3 makes code pretty big, and
it's not very practical to compile whole app level code with it (I'm
getting a 27MB executable - vs. 10.8MB), and it's the app code
which holds most of these constructs, at the end, the final app
cannot benefit much from it, certainly not size-wise.
I'm surprised a little. Our company is small but event our largest
application (has more than 100 browses and more than 100 dialogs,
everything in full GUI widgets) is about 2.5MB size (-gc2). That kind of
application should be to reach 10.8MB exe size?! :)
Regards,
Mindaugas
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour