plugins/testsuite/benchmark.sp
author David Anderson <dvander@alliedmods.net>
Sat May 17 05:12:52 2008 +0000 (2008-05-17)
changeset 2056 f1fcde46ac7c
parent 1952 b7aa2b626807
permissions -rw-r--r--
added amb1119 - sm_revote command
ds@1952
     1
#include <sourcemod>
ds@1952
     2
#include <profiler>
ds@1952
     3
ds@1952
     4
public Plugin:myinfo = 
ds@1952
     5
{
ds@1952
     6
	name = "Benchmarks",
ds@1952
     7
	author = "AlliedModders LLC",
ds@1952
     8
	description = "Basic benchmarks",
ds@1952
     9
	version = "1.0.0.0",
ds@1952
    10
	url = "http://www.sourcemod.net/"
ds@1952
    11
};
ds@1952
    12
ds@1952
    13
#define MATH_INT_LOOPS		2000
ds@1952
    14
#define MATH_FLOAT_LOOPS	2000
ds@1952
    15
#define STRING_OP_LOOPS		2000
ds@1952
    16
#define STRING_FMT_LOOPS	2000
ds@1952
    17
#define STRING_ML_LOOPS		2000
ds@1952
    18
#define STRING_RPLC_LOOPS	2000
ds@1952
    19
ds@1952
    20
new Float:g_dict_time
ds@1952
    21
new Handle:g_Prof = INVALID_HANDLE
ds@1952
    22
ds@1952
    23
public OnPluginStart()
ds@1952
    24
{
ds@1952
    25
	RegServerCmd("bench", Benchmark);
ds@1952
    26
	g_Prof = CreateProfiler();
ds@1952
    27
	StartProfiling(g_Prof);
ds@1952
    28
	LoadTranslations("fakedict-sourcemod.cfg");
ds@1952
    29
	StopProfiling(g_Prof);
ds@1952
    30
	g_dict_time = GetProfilerTime(g_Prof);
ds@1952
    31
}
ds@1952
    32
ds@1952
    33
public Action:Benchmark(args)
ds@1952
    34
{
ds@1952
    35
	PrintToServer("dictionary time: %f seconds", g_dict_time);
ds@1952
    36
	StringBench();
ds@1952
    37
	MathBench();
ds@1952
    38
	return Plugin_Handled;
ds@1952
    39
}
ds@1952
    40
ds@1952
    41
MathBench()
ds@1952
    42
{
ds@1952
    43
	StartProfiling(g_Prof);
ds@1952
    44
	new iter = MATH_INT_LOOPS;
ds@1952
    45
	new a, b, c;
ds@1952
    46
	while(iter--)
ds@1952
    47
	{
ds@1952
    48
		a = iter * 7;
ds@1952
    49
		b = 5 + iter;
ds@1952
    50
		c = 6 / (iter + 3);
ds@1952
    51
		a = 6 * (iter);
ds@1952
    52
		b = a * 185;
ds@1952
    53
		a = b / 25;
ds@1952
    54
		c = b - a + 3;
ds@1952
    55
		b = b*b;
ds@1952
    56
		a = (a + c) / (b - c);
ds@1952
    57
		b = 6;
ds@1952
    58
		c = 1;
ds@1952
    59
		b = a * 128 - c;
ds@1952
    60
		c = b * (a + 16) * b;
ds@1952
    61
		if (!a)
ds@1952
    62
		{
ds@1952
    63
			a = 5;
ds@1952
    64
		}
ds@1952
    65
		a = c + (28/a) - c;
ds@1952
    66
	}
ds@1952
    67
	StopProfiling(g_Prof);
ds@1952
    68
	PrintToServer("int benchmark: %f seconds", GetProfilerTime(g_Prof));
ds@1952
    69
ds@1952
    70
	StartProfiling(g_Prof);	
ds@1952
    71
	new Float:fa, Float:fb, Float:fc
ds@1952
    72
	new int1
ds@1952
    73
	iter = MATH_FLOAT_LOOPS;
ds@1952
    74
	while (iter--)
ds@1952
    75
	{
ds@1952
    76
		fa = iter * 0.7;
ds@1952
    77
		fb = 5.1 + iter;
ds@1952
    78
		fc = 6.1 / (float(iter) + 2.5);
ds@1952
    79
		fa = 6.1 * (iter);
ds@1952
    80
		fb = fa * 185.26;
ds@1952
    81
		fa = fb / 25.56;
ds@1952
    82
		fc = fb - a + float(3);
ds@1952
    83
		fb = fb*fb;
ds@1952
    84
		fa = (fa + fc) / (fb - fc);
ds@1952
    85
		fb = 6.2;
ds@1952
    86
		fc = float(1);
ds@1952
    87
		int1 = RoundToNearest(fa);
ds@1952
    88
		fb = fa * float(128) - int1;
ds@1952
    89
		fc = fb * (a + 16.85) * float(RoundToCeil(fb));
ds@1952
    90
		if (fa == 0.0)
ds@1952
    91
		{
ds@1952
    92
			fa = 5.0;
ds@1952
    93
		}
ds@1952
    94
		fa = fc + (float(28)/fa) - RoundToFloor(fc);
ds@1952
    95
	}
ds@1952
    96
	StopProfiling(g_Prof);
ds@1952
    97
	PrintToServer("float benchmark: %f seconds", GetProfilerTime(g_Prof));
ds@1952
    98
}
ds@1952
    99
ds@1952
   100
#define KEY1	"LVWANBAGVXSXUGB"
ds@1952
   101
#define KEY2	"IDYCVNWEOWNND"
ds@1952
   102
#define KEY3	"UZWTRNHY"
ds@1952
   103
#define KEY4	"EPRHAFCIUOIG"
ds@1952
   104
#define KEY5	"RMZCVWIEY"
ds@1952
   105
#define KEY6	"ZHPU"
ds@1952
   106
ds@1952
   107
StringBench()
ds@1952
   108
{
ds@1952
   109
	new i = STRING_FMT_LOOPS;
ds@1952
   110
	new String:buffer[255];
ds@1952
   111
	
ds@1952
   112
	StartProfiling(g_Prof);
ds@1952
   113
	new end
ds@1952
   114
	while (i--)
ds@1952
   115
	{
ds@1952
   116
		end = 0;
ds@1952
   117
		Format(buffer, sizeof(buffer), "%d", i);
ds@1952
   118
		Format(buffer, sizeof(buffer), "%d %s %d %f %d %-3.4s %s", i, "gaben", 30, 10.0, 20, "hello", "What a gaben");
ds@1952
   119
		end = Format(buffer, sizeof(buffer), "Well, that's just %-17.18s!", "what.  this isn't a valid string! wait it is");
ds@1952
   120
		end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
ds@1952
   121
		end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
ds@1952
   122
	}
ds@1952
   123
	StopProfiling(g_Prof);
ds@1952
   124
	PrintToServer("format() benchmark: %f seconds", GetProfilerTime(g_Prof));
ds@1952
   125
	
ds@1952
   126
	StartProfiling(g_Prof);
ds@1952
   127
	i = STRING_ML_LOOPS;
ds@1952
   128
	new String:fmtbuf[2048];	/* don't change to decl, amxmodx doesn't use it */
ds@1952
   129
	while (i--)
ds@1952
   130
	{
ds@1952
   131
		Format(fmtbuf, 2047, "%T %T %d %s %f %T", KEY1, LANG_SERVER, KEY2, LANG_SERVER, 50, "what the", 50.0, KEY3, LANG_SERVER);
ds@1952
   132
		Format(fmtbuf, 2047, "%s %T %s %T %T", "gaben", KEY4, LANG_SERVER, "what TIME is it", KEY5, LANG_SERVER, KEY6, LANG_SERVER);
ds@1952
   133
	}
ds@1952
   134
	StopProfiling(g_Prof);
ds@1952
   135
	PrintToServer("ml benchmark: %f seconds", GetProfilerTime(g_Prof));
ds@1952
   136
	
ds@1952
   137
	StartProfiling(g_Prof);
ds@1952
   138
	i = STRING_OP_LOOPS;
ds@1952
   139
	while (i--)
ds@1952
   140
	{
ds@1952
   141
		StringToInt(fmtbuf)
ds@1952
   142
	}
ds@1952
   143
	StopProfiling(g_Prof);
ds@1952
   144
	PrintToServer("str benchmark: %f seconds", GetProfilerTime(g_Prof));
ds@1952
   145
	
ds@1952
   146
	StartProfiling(g_Prof);
ds@1952
   147
	i = STRING_RPLC_LOOPS;
ds@1952
   148
	while (i--)
ds@1952
   149
	{
ds@1952
   150
		strcopy(fmtbuf, 2047, "This is a test string for you.");
ds@1952
   151
		ReplaceString(fmtbuf, sizeof(fmtbuf), " ", "ASDF")
ds@1952
   152
		ReplaceString(fmtbuf, sizeof(fmtbuf), "SDF", "")
ds@1952
   153
		ReplaceString(fmtbuf, sizeof(fmtbuf), "string", "gnirts")
ds@1952
   154
	}
ds@1952
   155
	StopProfiling(g_Prof);
ds@1952
   156
	PrintToServer("replace benchmark: %f seconds", GetProfilerTime(g_Prof));
ds@1952
   157
}