SA-MP Forums Archive
Testing Code - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Testing Code (/showthread.php?tid=282449)



Testing Code - Skywalkerz - 11.09.2011

HI guys,

I've recently tested a code

it was to see which is better

I followed ******' string optimisation thread

that i made i test with

new str[12 char]

vs

new string[12]

pawn Код:
#define ITERATIONS (10000)

Test()
{
    new
        t0,
        t1,
        t2,
        i;
    t0 = GetTickCount();
    for (i = 0; i < ITERATIONS; i++)
    {
        new str[12 char] = !"Hello there";
        printf(str);
    }
    t1 = GetTickCount();
    for (i = 0; i < ITERATIONS; i++)
    {
        new string[12] = "Hello there";
        printf(string);
    }
    t2 = GetTickCount();
    printf("Time 1: %04d, time 2: %04d", t1 - t0, t2 - t1);
}
But i deleted the code after tested and also the result
luckily i can still remember it(partially)
The result is: Time 1: 2900 Something Time 2: 2800 Something

but thats not the point, the point is time 1 which is a packed string has more time than time 2.

I'm not sure which is better + Did it count the time to finish all printf's or did it count the time it has been printed?


Re: Testing Code - Skywalkerz - 11.09.2011

bump anyone help please (


Re: Testing Code - Sasino97 - 11.09.2011

Quote:
Originally Posted by Skywalkerz
Посмотреть сообщение
HI guys,

I've recently tested a code

it was to see which is better

I followed ******' string optimisation thread

that i made i test with

new str[12 char]

vs

new string[12]

pawn Код:
#define ITERATIONS (10000)

Test()
{
    new
        t0,
        t1,
        t2,
        i;
    t0 = GetTickCount();
    for (i = 0; i < ITERATIONS; i++)
    {
        new str[12 char] = !"Hello there";
        printf(str);
    }
    t1 = GetTickCount();
    for (i = 0; i < ITERATIONS; i++)
    {
        new string[12] = "Hello there";
        printf(string);
    }
    t2 = GetTickCount();
    printf("Time 1: %04d, time 2: %04d", t1 - t0, t2 - t1);
}
But i deleted the code after tested and also the result
luckily i can still remember it(partially)
The result is: Time 1: 2900 Something Time 2: 2800 Something

but thats not the point, the point is time 1 which is a packed string has more time than time 2.

I'm not sure which is better + Did it count the time to finish all printf's or did it count the time it has been printed?
It counted from the start of a print til the end of the loop.

pawn Код:
t1 = GetTickCount(); // Put into t1 the ms have passed since the start
    for (i = 0; i < ITERATIONS; i++)
    {
        new string[12] = "Hello there"; //
        printf(string); // Prints 10000 times "Hello there"
    }
    t2 = GetTickCount(); // Then get again the ms count
2800 is the time that passed for printing 10k times "Hello there"

Try what happens if you write:

pawn Код:
#define ITERATIONS (10000)

Test()
{
    new
        t0,
        t1,
        t2,
        i;
    t0 = GetTickCount();
    for (i = 0; i < ITERATIONS; i++)
    {
        printf(!"Hello there");
    }
    t1 = GetTickCount();
    for (i = 0; i < ITERATIONS; i++)
    {
        printf("Hello there");
    }
    t2 = GetTickCount();
    printf("Time 1: %04d, time 2: %04d", t1 - t0, t2 - t1);
}



Re: Testing Code - iggy1 - 11.09.2011

Packed strings are slower (than standard strings) because they need to be packed/unpacked, but they use much less memory.