Testing Code
#1

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?
Reply
#2

bump anyone help please (
Reply
#3

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);
}
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)