Difference between revisions of "User:Pedro Oval/Mono code memory usage"
Jump to navigation
Jump to search
Pedro Oval (talk | contribs) (Add note on x&&y and x||y) |
Pedro Oval (talk | contribs) m (Oops, should have previewed the former edit) |
||
Line 71: | Line 71: | ||
| x&y || 4 || Bitwise | | x&y || 4 || Bitwise | ||
|- | |- | ||
| x&&y || 13 || Logical. Same bytes as, and equivalent to, !(!x|!y) | | x&&y || 13 || Logical. Same bytes as, and equivalent to, !(!x<nowiki>|</nowiki>!y) | ||
|- | |- | ||
| x<nowiki>|</nowiki>y || 4 || Bitwise | | x<nowiki>|</nowiki>y || 4 || Bitwise | ||
|- | |- | ||
| x<nowiki>||</nowiki>y || 10 || Logical. Same bytes as, and equivalent to, !!(x|y) | | x<nowiki>||</nowiki>y || 10 || Logical. Same bytes as, and equivalent to, !!(x<nowiki>|</nowiki>y) | ||
|- | |- | ||
| x^y || 4 || Bitwise | | x^y || 4 || Bitwise |
Revision as of 08:21, 21 June 2013
Here are some memory usage results I've obtained with Mono, for common language constructs. They were obtained by replicating each line to test 512 times and looking at llGetFreeMemory right at the beginning of the script.
Results for local integer variables x, y, and local float variables f, g:
Construct | Bytes used | Comments |
---|---|---|
; | 0 | |
{} | 0 | |
return | 1 | Tested in event and without arguments |
x | 2 | |
(x) | 2 | |
(integer)x | 2 | |
(float)x | 3 | |
f | 2 | |
(float)f | 2 | |
(integer)f | 7 | |
-x | 3 | |
~x | 3 | Bitwise, equivalent to -x-1 which allows it to be used for some hacks. Not applicable to floats though. |
!x | 5 | Logical |
--x | 6 | Pre-decrement (same bytes as x=~-x) |
++x | 6 | Pre-increment (same bytes as x=-~x) |
x-- | 8 | Post-decrement |
x++ | 8 | Post-increment |
x=y | 4 | Assignment |
x==y | 5 | Comparison |
x=y=z | 6 | (for local integer z) Chained assignment |
f=x | 5 | Implicit conversion from integer to float |
f=(float)x | 5 | Explicit conversion from integer to float |
x!=y | 8 | Same bytes as !(x==y) |
x*y | 4 | |
x/y | 8 | |
x%y | 8 | Modulo |
x+y | 4 | |
x-y | 8 | !?!? |
x+-y | 5 | Saves 3 bytes vs. a subtraction! |
x*y | 4 | |
x/y | 8 | |
x&y | 4 | Bitwise |
x&&y | 13 | Logical. Same bytes as, and equivalent to, !(!x|!y) |
x|y | 4 | Bitwise |
x||y | 10 | Logical. Same bytes as, and equivalent to, !!(x|y) |
x^y | 4 | Bitwise |
x<<y | 8 | Bitwise shift left (can be simulated with mult in most cases) |
x>>y | 8 | Bitwise shift right |
x<y | 5 | |
x>y | 5 | |
x<=y | 8 | Same bytes as !(x>y) |
x>=y | 8 | Same bytes as !(x<y) |
x+=y | 6 | Same bytes as x=x+y |
x-=y | 10 | Same bytes as x=x-y |
x+=-y | 7 | Saves 3 bytes vs x-=y |
x*=y | 6 | Same as x=x*y |
x/=y | 10 | Same as x=x/y |
x%=y | 10 | Same as x=x%y |
if(x); | 6 | |
if(x); else; | 11 | |
0 | 6 | |
x^x | 4 | It gives always 0, saving 2 bytes. (Thanks to User:Omei Qunhua for the discovery) |
1 | 6 | |
-1 | 7 | Sign takes code memory. |
0xffffffff | 6 | Equivalent to -1. |
ALL_SIDES | 6 | Value is -1. Constants with negative values don't take memory for the sign. |
x|~x | 5 | Equivalent to -1. Saves 1 byte vs 0xffffffff, 2 bytes vs -1. |
x+1 | 8 | |
-~x | 4 | Same as x+1, saves 4 bytes |
x-1 | 12 | What's wrong with subtraction? |
x+-1 | 9 | Same as x-1, saves 3 bytes |
~-x | 4 | Same as x-1, saves 8 bytes |
x*y+y-1 | 16 | This kind of construct is sometimes used to access last element of strided lists |
(x+1)*y-1 | 20 | Equivalent to the above, just worse |
~(~x*y) | 6 | Equivalent to the above, saves 10 bytes |
while(x); | 37 | |
do ; while(x); | 41 | Unexpected but true |
for(;x;); | 37 | For loops seem to be plainly rewritten as while loops |
@label; if(x) jump label; | 37 | Equivalent to a do...while loop, saves 4 bytes. |
0.0 | 10 | Float constants use a lot of memory. |
f=0.0 | 12 | |
f=0 | 9 | In general, using integer constants with implicit conversion to float instead of float constants saves 3 bytes every time. Another example follows. |
<0.0, 0.0, 0.0> | 33 | Same as ZERO_VECTOR |
ZERO_VECTOR | 33 | |
<0, 0, 0> | 24 | Saves 3 bytes per constant |
<-1.0, -1.0, 0.0> | 35 | (because of the signs). Equivalent to TOUCH_INVALID_TEXCOORD. |
TOUCH_INVALID_TEXCOORD | 33 | |
<-1, -1, 0> | 26 | (because of the signs) |
<0xffffffff, 0xffffffff, 0> | 24 | (no signs but ugly) |