[Tutorial] Creative & smart scripting techniques - improve performance & readablity in one go
#32

Quote:
Originally Posted by Jefff
View Post
1.
Code:
new pInfo[MAX_PLAYERS + 1][PlayerInfo];
2. I don't know for what is here memcpy
Code:
pInfo[playerid] = pInfo[MAX_PLAYERS];
memcpy is actually faster that direct assignment when your array is VERY BIG.

Quote:
Originally Posted by Uberanwar
View Post
Hey Yashas, thank you for this useful & helpful knowledge you've shared to the community. keep it up

I'm having an error and a warning though, need help on this..

warning 229: index tag mismatch (symbol "pInfo")
error 032: array index out of bounds (variable "pInfo")

both on the same line which is

^ that one
I guess its because of the sizeof, try sizeof(pInfo[][]) or something similar. I have lost touch with PAWN and I do not remember. A bit of tweaking should fix the problem.


Quote:
Originally Posted by Day_
View Post
This
PHP Code:
new Float:Coords[5][4] = {
    {
0.00.10.20.3},
    {
1.01.11.21.3},
    {
2.02.12.22.3},
    {
3.03.13.23.3},
    {
4.04.14.24.3}
};
function(){
    new 
rand random(sizeof(Coords));
    foreach(new 
iPlayer)
    {
        
SetPlayerPos(playeridCoords[rand][0], Coords[rand][1], Coords[rand][2]);
        
SetPlayerFacingAngle(playeridCoords[rand][3]);
    }
    
CreatePickup(12Coords[rand][0], Coords[rand][1], Coords[rand][2]);
    
Create3DTextLabel("You are here", -1Coords[rand][0], Coords[rand][1], Coords[rand][2], 15.00);

is Slower than this
PHP Code:
new Float:Coords[5][4] = {
    {
0.00.10.20.3},
    {
1.01.11.21.3},
    {
2.02.12.22.3},
    {
3.03.13.23.3},
    {
4.04.14.24.3}
};
function(){
    new 
rand random(sizeof(Coords));
    new 
        
Float:X        Coords[rand][0],
        
Float:Y        Coords[rand][1],
        
Float:Z        Coords[rand][2],
        
Float:Ang    Coords[rand][3]
    ;
    foreach(new 
iPlayer)
    {
        
SetPlayerPos(playeridXYZ);
        
SetPlayerFacingAngle(playeridCoords[rand][3]);
    }
    
CreatePickup(12XYZ);
    
Create3DTextLabel("You are here", -1XYZ15.00);

The functions are example.

I think, because every time at Coords[*] is called, need load the value i and the value from Coords, if you use the array only a time no have differences between speed.

Sorry my bad english, someone smarter than me can explain better.
It is well explained here (Click) with proof.

Quote:
Originally Posted by OneDay
View Post
new gPlayerInfo[MAX_PLAYERS][PlayerData];
new playerInfo[PlayerData];

gPlayerInfo[playerid]=playerInfo;

is not function memcpy is pawn faster than function memcpy
IIRC memcpy is faster when the array is pretty huge. The improvement is however negligible since either way its WAY WAY WAY faster than the loop method to reset an array (the speed difference b/w memcpy and direct assignment doesn't matter here - I have explained it in on of my previous replies to SickAttack).

Quote:
Originally Posted by Untonyst
View Post
  1. If you are looking for a only one symbol, it is better to use a loop.
  2. If necessary to use a for loop for the whole string, it is not necessary to know the size of the string.


    PHP Code:
    new string[128] = "qw;lasdl;k1l;k2l;4k;"// :D
    for (new i/* none */ ;i++)
    {
        if (
    string[i] == 'l')
        {
            
    // do something
            // ...
            // loop is complete
            
    break;
        }
        
    // cycle is complete
        // if symbol is not found
        
    if (string[i] == '\0')
        {
            break;
        }

    or

    PHP Code:
    new string[128] = "qw;lasdl;k1l;k2l;4k;",
        
    i;
    while (
    string[i++] != '\0')
    {
        if (
    string[i] == 'l')
        {        
            
    // do something
            // ...
            // loop is complete
            
    break;
        }

  3. For more optimization you can use variables, so often not to refer to the array index.

    PHP Code:
    new string[128] = "qw;lasdl;k1l;k2l;4k;"
        
    c,    // is values of the array index 
        
    i     // index 

    while ((
    string[i++]) != '\0')
    {
        if (
    == 'l')
        {        
            
    // do something
            // ...
            // loop is complete
            
    break;
        }

  4. If the condition need to compare three numbers, it is possible to make it so
    PHP Code:
    new value 7;
    if (
    <= value <= 9)
    {
        
    // do something

Your loop is horribley slow compared to strfind. Strfind accepts a substring instead of a character but its still faster when you want to search for a character.

Check Natives are faster than PAWN code in this (Click)topic to know more.

Quote:
Originally Posted by OneDay
View Post
the second code is wrong because ++ but just use strfind
1. strfind is faster than that code
2. His code has a bug. It skips a character.

Quote:
Originally Posted by Crayder
View Post
No, it's not wrong. Learn PAWN before trying to call someone out like that.
His English isn't good lol

He wanted to say that there is a bug and that code wont work because of i++ but he said it in a completely wrong and misleading way.
Reply


Messages In This Thread
Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 25.06.2016, 16:16
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by iKarim - 25.06.2016, 17:20
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Crayder - 25.06.2016, 17:56
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Konstantinos - 25.06.2016, 18:05
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Battlezone - 27.06.2016, 20:54
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by PrO.GameR - 28.06.2016, 14:40
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Vince - 28.06.2016, 15:18
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by CodeStyle175 - 28.06.2016, 16:28
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by PrO.GameR - 28.06.2016, 17:01
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by iKarim - 28.06.2016, 19:24
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Freedom. - 28.06.2016, 20:33
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by iKarim - 28.06.2016, 21:54
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by PrO.GameR - 29.06.2016, 00:35
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by DavidBilla - 04.07.2016, 19:32
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Crayder - 04.07.2016, 20:32
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 06.07.2016, 14:30
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by K0P - 06.07.2016, 14:36
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by SickAttack - 06.07.2016, 14:44
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 06.07.2016, 14:51
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by SickAttack - 06.07.2016, 15:26
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 06.07.2016, 15:33
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by SickAttack - 06.07.2016, 15:47
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 06.07.2016, 16:26
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Uberanwar - 08.07.2016, 16:35
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Jefff - 09.07.2016, 02:08
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Dayvison_ - 12.07.2016, 01:16
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by OneDay - 12.07.2016, 18:55
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Untonyst - 13.07.2016, 22:34
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by OneDay - 14.07.2016, 01:00
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Crayder - 14.07.2016, 02:39
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by OneDay - 14.07.2016, 15:23
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 15.07.2016, 12:29
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by OneDay - 18.07.2016, 17:09
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Sasino97 - 16.07.2017, 16:31
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by ][Noname][ - 24.11.2017, 13:11
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 17.12.2017, 15:52
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by VincenzoDrift - 01.01.2018, 16:07
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by ][Noname][ - 15.01.2018, 11:53
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Kaperstone - 16.01.2018, 00:54
Re: Creative & smart scripting techniques - improve performance & readablity in one go - by Yashas - 31.01.2018, 18:55

Forum Jump:


Users browsing this thread: 3 Guest(s)