26.09.2018, 17:48
Quote:
I don't use YSI, so I haven't measured the difference, but I am interested in the results, if you decide to compare the containers. The containers and iterators use the standard C++ classes, with some minor overhead due to safety checks, so it still might be faster than some other Pawn implementation (like pawn-vector), but it depends on a lot of factors.
|
Today I wanted to try something else, to see whether map_str_add_str would be faster than SetSVarString, here's the results and the code.
Code:
[19:32:44] Bench for Store string 'Haha, this is a benchmark' in a PVar.: executes, by average, 1520.13 times/ms. [19:32:46] Bench for Store string 'Haha, this is a benchmark' in a normal variable with strcat.: executes, by average, 1984.01 times/ms. [19:32:48] Bench for Store string 'Haha, this is a benchmark' in a PawnPlus map with SA-MP string.: executes, by average, 1070.41 times/ms. [19:32:50] Bench for Store string 'Haha, this is a benchmark' in a PawnPlus map with PawnPlus string.: executes, by average, 620.31 times/ms.
pawn Code:
#include <a_samp>
#include <pawnplus>
#define START_BENCH(%0); {new __a=%0,__b=0,__c,__d=GetTickCount(),__e=1;do{}\
while(__d==GetTickCount());__c=GetTickCount();__d=__c;while(__c-__d<__a||\
__e){if(__e){if(__c-__d>=__a){__e=0;__c=GetTickCount();do{}while(__c==\
GetTickCount());__c=GetTickCount();__d=__c;__b=0;}}{
#define FINISH_BENCH(%0); }__b++;__c=GetTickCount();}printf(" Bench for "\
%0": executes, by average, %.2f times/ms.",floatdiv(__b,__a));}
new teststring[50],
Map:ppteststring;
public OnFilterScriptInit()
{
ppteststring = map_new();
START_BENCH( 1000 );
{
SetSVarString("benchmark", "Haha, this is a benchmark");
}
FINISH_BENCH( "Store string 'Haha, this is a benchmark' in a PVar.");
START_BENCH( 1000 );
{
strcat(teststring, "Haha, this is a benchmark");
}
FINISH_BENCH( "Store string 'Haha, this is a benchmark' in a normal variable with strcat.");
START_BENCH( 1000 );
{
map_str_add_str(ppteststring, "benchmark", "Haha, this is a benchmark");
}
FINISH_BENCH( "Store string 'Haha, this is a benchmark' in a PawnPlus map with SA-MP string.");
START_BENCH( 1000 );
{
map_str_add(ppteststring, "benchmark", str_new("Haha, this is a benchmark"));
}
FINISH_BENCH( "Store string 'Haha, this is a benchmark' in a PawnPlus map with PawnPlus string.");
return 1;
}