I wrote a small test to check for inliningof functions in for loops.
#define CAKE1 ;a += 5;c -= b;d = a + b + c;
#define CAKE2 ;a = 0;b = 2;c = 1;d = 0;
#define CAKE3 ;a = 0;b = 2;c = 1;d = 0;
mob
var
a = 0
b = 2
c = 1
d = 0
proc
cake1()
a += 5
c -= b
d = a + b + c
cake2()
a = 0
b = 2
c = 1
d = 0
cake3()
a = 0
b = 2
c = 1
d = 0
verb
show_vars()
world << "[a] [b] [c] [d]"
test_proc(loops as num)
set background = TRUE
world << "test_proc started with [loops] iterations"
var/start = world.time
for(var/i = 0, i < loops, i++)
cake1()
cake2()
cake1()
cake3()
cake1()
cake2()
cake1()
cake3()
world << (world.time - start)
test_prec_macro(loops as num)
set background = TRUE
world << "test_prec_macro started with [loops] iterations"
var/start = world.time
for(var/i = 0, i < loops, i++)
CAKE1
CAKE2
CAKE1
CAKE3
CAKE1
CAKE2
CAKE1
CAKE3
world << (world.time - start)
The purpose of this was testing the overhead of calling functions against using macros, i other words inlining the code.
The test verbs show results when using values of at least 1000 000 loops, and as expected the macro version performs better.
The thing is maybe i did my macros wrong :-O, maybe you can tell me if that is the case ;-)
The strange thing is, that after running both versions one or two times, they seem to get faster, and then after a few time the get back to the old performance. (maybe due to my processor changing FSB Frequency)
Does anyone have some information what kind of optimization regarding function inlining the compiler can do?
A few assumptions so far:
- Functions are not inlned
- Functions are not inlned in for-loops
- for-loops are not inlined (if they contain fuctions????)
Possible reasons:
-BYOND allows to add and remove functions and verbs from/to objects, so the compiler may be unable to assure it is the same function called?
-I did my Macros wrong :-)