PAWN architecture - references vs return
#1

Wow, havent opened a topic in Scripting discussion for ages.
However, a row of random events lead me to a simple performance experiment, regarding references and direct returns of functions in pawn.
The question might be one of the least important question ever, but Im just asking out of curiousness, and Id like to see if anyone here got an answer for that.

Lets take a look at these two functions:
pawn Code:
stock functionA()
{
    return 1;
}
stock functionB(&result)
{
    result = 1;
}
As you can see, basically both do the same, just with the difference that functionA directly returns 1, and functionB passes 1 to a reference.
Now lets test their speed with 3 different tests: http://pastebin.com/BDxtgzWS

Results:
Test 1: functionA: 455 ms, functionB 515 ms
Test 2: functionA: 660 ms, functionB 615 ms
Test 3: functionA: 515 ms, functionB 615 ms

And heres the question: Why is functionA faster in Test 1 and 3, but slower in Test 2? I dont think someone without deeper pawn architecture knowledge can tell something about that, but I thought i could give it a try

BTW: What we learn from Test 2/3 is, never assign values to variables directly when creating them, but just in a new line, and it is almost 25% faster (Isnt that something the compiler should detect and optimize automatically?)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)