Quote:
Originally Posted by IstuntmanI
Code used:
pawn Код:
public OnFilterScriptInit( ) { new liTick;
#define ITERS 1000000
//============================[ Set Int ]=================================== // GVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) SetGVarInt( "TestSI", 69 );
printf( "INT: Set: GVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
// SVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) SetSVarInt( "TestSI", 69 );
printf( "INT: Set: SVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
//============================[ Get Int ]=================================== // GVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) GetGVarInt( "TestGI" );
printf( "INT: Get: GVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
// SVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) GetSVarInt( "TestGI" );
printf( "INT: Get: SVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
//===========================[ Set Float ]================================== // GVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) SetGVarFloat( "TestSF", 69.00 );
printf( "FLOAT: Set: GVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
// SVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) SetSVarFloat( "TestSF", 69.00 );
printf( "FLOAT: Set: SVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
//===========================[ Get Float ]================================== // GVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) GetGVarFloat( "TestGF" );
printf( "FLOAT: Get: GVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
// SVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) GetSVarFloat( "TestGF" );
printf( "FLOAT: Get: SVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
//===========================[ Set String ]================================= // GVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) SetGVarString( "TestSS", "Sixty Nine" );
printf( "STRING: Set: GVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
// SVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) SetSVarString( "TestSS", "Sixty Nine" );
printf( "STRING: Set: SVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
//===========================[ Get String ]================================= new lsString[ 16 ];
// GVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) GetGVarString( "TestGS", lsString, 16 );
printf( "STRING: Get: GVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
// SVar liTick = GetTickCount( );
for( new i = 0; i < ITERS; i ++ ) GetSVarString( "TestGS", lsString, 16 );
printf( "STRING: Get: SVar speed for %d iterations: %dms", ITERS, GetTickCount( ) - liTick );
return 1; }
Results:
So SVars are slower only at setting strings.
|
That's not entirely accurate. You're only allocating one element each time. I've only tested integers, but here's what I got by allocating 100,000 unique elements:
pawn Код:
new names[100000][16];
for (new i = 0; i < 100000; i++)
{
format(names[i], sizeof(names[]), "name_%d", i);
}
pawn Код:
new time = GetTickCount();
for (new i = 0; i < 100000; i++)
{
SetGVarInt(names[i], i);
}
printf("Time #1: %d", GetTickCount() - time);
time = GetTickCount();
for (new i = 0; i < 100000; i++)
{
GetGVarInt(names[i]);
}
printf("Time #2: %d", GetTickCount() - time);
Код:
[19:03:10] Time #1: 54
[19:03:10] Time #2: 35
pawn Код:
new time = GetTickCount();
for (new i = 0; i < 100000; i++)
{
SetSVarInt(names[i], i);
}
printf("Time #1: %d", GetTickCount() - time);
time = GetTickCount();
for (new i = 0; i < 100000; i++)
{
GetSVarInt(names[i], i);
}
printf("Time #2: %d", GetTickCount() - time);
Код:
[19:04:05] Time #1: 1089
[19:04:06] Time #2: 1004
SVars are big improvement over properties, but they still seem to be slightly slower than GVars as they increase in number. I assume a hash table implementation wasn't used.
As for your suggestion: yes, I suppose that could be done pretty easily. JernejL also suggested iteration support to me a while back, but I haven't found the time to see about adding it yet.