[Benchmark] strpack vs format
#1

I made a quick benchmark script to see which was faster, just sharing them here for the record:
pawn Код:
#include <a_samp>

main()
{
    new
        StartTick,
        StopTick,
        string[16],
        string2[16];
       
    format(string2, 17, "I like big butts");
    StartTick = GetTickCount();
    for(new i; i < 1000000; i++)
    {
        format(string, 17, string2);
    }
    StopTick = GetTickCount();
    printf("format: %d ms", StopTick-StartTick);
    for(new i; i < 1000000; i++)
    {
        strpack(string, string2, 17);
    }
    StopTick = GetTickCount();
    printf("strpack: %d ms", StopTick-StartTick);
    return 1;
}
Result:
[21:40:19] format: 351 ms
[21:40:19] strpack: 524 ms

Conclusion: format is faster.
Reply
#2

k

Код:
The message you have entered is too short. Please lengthen your message to at least 4 characters.
Reply
#3

Cool, that's nice to know
Reply
#4

Shouldn't you re-fetch StartTick after the first code executes? If not, aren't you taking the time it takes for format AND strpack to execute (aka when the server started), which is not what you want. You want the time each section of code took to execute. I did that and got this:

Код:
format: 319 ms
strpack: 137 ms
pawn Код:
#include <a_samp>

main()
{
    new
        StartTick,
        StopTick,
        string[16],
        string2[16];

    format(string2, 17, "I like big butts");
    StartTick = GetTickCount();
    for(new i; i < 1000000; i++)
    {
        format(string, 17, string2);
    }
    StopTick = GetTickCount();
    printf("format: %d ms", StopTick-StartTick);
    StartTick = GetTickCount();
    for(new i; i < 1000000; i++)
    {
        strpack(string, string2, 17);
    }
    StopTick = GetTickCount();
    printf("strpack: %d ms", StopTick-StartTick);
    return 1;
}
Reply
#5

Haha Jesus, sorry you're right I was a bit tired, guess that's why I missed that!
Reply
#6

so strpack was like expected faster but what has format to do with strpack or vica versa ?
Reply
#7

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
so strpack was like expected faster but what has format to do with strpack or vica versa ?
My question too. You can't effectively use strpack to put arguments into a string. You would have to use strins which would be difficult, time-consuming, and inefficient.
Reply
#8

I often see people use format to copy a string to another, so I was curious to see which way was actually more effective. Like I said I'm only posting it here for the record, so it's somewhere to be found
Reply
#9

Than you missed to read that topic => Code optimisation
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)