SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 05/06/2011, 09:58 PM   #1
Mauzen
High-roller
 
Mauzen's Avatar
 
Join Date: Jun 2007
Location: Western Germany
Posts: 4,878
Reputation: 1597
Default PAWN architecture - references vs return

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?)

Last edited by Mauzen; 05/06/2011 at 10:49 PM.
Mauzen is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to pawn, trying to convert some C code to pawn CHC Scripting Help 2 22/06/2012 05:09 AM
[HELP] [pawn][/pawn] bbcode for phpbb3 Kasura Help Archive 4 20/11/2010 04:35 AM
Plugin does not conform to architecture hansen111 Plugin Development 9 27/10/2009 09:02 PM


All times are GMT. The time now is 07:40 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.