|
Great Tester of Whatever
|
08-01-2020
, 07:03
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
|
#39
|
I'll just leave it as information maybe it will be useful for someone
INT & BOOL & FLOAT
PHP Code:
Bench: Min 0.000016. Avg 0.000016. Max 0.000017 - g_iTest = GetConVarInt(vs_max_team_switches);
Bench: Min 0.000001. Avg 0.000001. Max 0.000002 - g_iTest = g_iConst; Bench: Min 0.000001. Avg 0.000001. Max 0.000002 - g_iTest = g_iValue;
Bench: Min 0.000001. Avg 0.000001. Max 0.000002 - g_iTest = g_flConst; Bench: Min 0.000001. Avg 0.000001. Max 0.000002 - g_iTest = g_flValue;
Bench: Min 0.000001. Avg 0.000002. Max 0.000002 - g_iTest = g_bByte; Bench: Min 0.000001. Avg 0.000002. Max 0.000002 - g_bBool = !g_bBool;
Bench: Min 0.000001. Avg 0.000002. Max 0.000002 { if (!g_bBool) g_bBool = true; else g_bBool = false; }
PROPERTY
PHP Code:
Bench: Min 0.000075. Avg 0.001785. Max 0.034192 - SetEntProp(0, Prop_Send, "m_bColdWorld", 1); Bench: Min 0.000017. Avg 0.000018. Max 0.000032 - SetEntData(0, g_iOffset, 1);
command
PHP Code:
Bench: Min 0.000006. Avg 0.000007. Max 0.000018 - sm_somecommand(client, 0); Bench: Min 0.001201. Avg 0.001476. Max 0.002383 - FakeClientCommand(client, "sm_somecommand"); Bench: Min 0.000213. Avg 0.000286. Max 0.000483 - ClientCommand(client, "sm_somecommand");
CHAR
PHP Code:
Bench: Min 0.000010. Avg 0.000011. Max 0.000012 - g_bBool = (strlen(szChar) > 0); Bench: Min 0.000001. Avg 0.000001. Max 0.000002 - g_bBool = (szChar[0] != '\0'); Bench: Min 0.000001. Avg 0.000001. Max 0.000002 - g_bBool = (szChar[0] != 0);
Bench: Min 0.000008. Avg 0.000008. Max 0.000009 - szChar = "S"; Bench: Min 0.000020. Avg 0.000024. Max 0.000057 - Format(szChar, 1, "S");
OTHER
PHP Code:
Bench: Min 0.000281. Avg 0.000476. Max 0.000763 { for( int i = 0; i < 1000; i++ ) { for (int l = 1; l <= MaxClients; l++) { if (IsClientInGame(l) && GetClientTeam(l) == 3 && IsPlayerAlive(l)) { g_bBool = true; } } } }
Bench: Min 0.000281. Avg 0.000299. Max 0.000421 { for( int i = 0; i < 1000; i++ ) { for (int l = 1; l <= MaxClients; l++) { if (!IsClientInGame(l) || GetClientTeam(l) != 3 || !IsPlayerAlive(l)) continue; g_bBool = true; } } }
Code
PHP Code:
/* Thanks Silvers for code to profiling */
#pragma newdecls required #pragma semicolon 1
#include <sourcemod> #include <profiler>
static const int g_iConst = 66666666; int g_iValue = 66666666;
static const float g_flConst = 66666666.6; float g_flValue = 66666666.6;
static const bool g_bByte = true;
ConVar vs_max_team_switches;
any g_iTest;
int g_iOffset;
bool g_bBool;
public void OnPluginStart() { g_iOffset = FindSendPropInfo("CWorld", "m_bColdWorld"); vs_max_team_switches = FindConVar("vs_max_team_switches"); RegAdminCmd("sm_test", sm_test, ADMFLAG_ROOT); RegAdminCmd("sm_somecommand", sm_somecommand, ADMFLAG_ROOT); }
public Action sm_somecommand (int client, int args) { }
public Action sm_test (int client, int args) { Handle hProf = CreateProfiler(); float min = 10.0, max, avg; // Running the test 20 times to gain min/max/avg for( int x = 0; x < 20; x++ ) { StartProfiling(hProf); // Running 1000 iterations for our test for( int i = 0; i < 1000; i++ ) { } StopProfiling(hProf); float speed = GetProfilerTime(hProf); if( speed < min ) min = speed; if( speed > max ) max = speed; avg += speed; } // Display our minimum, maximum and average times. avg /= 20; PrintToServer("Bench: Min %f. Avg %f. Max %f", min, avg, max); delete hProf; }
__________________
Last edited by BHaType; 08-01-2020 at 07:09.
|
|
|
|