plugins/testsuite/benchmark.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/testsuite/benchmark.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,157 +0,0 @@
     1.4 -#include <sourcemod>
     1.5 -#include <profiler>
     1.6 -
     1.7 -public Plugin:myinfo = 
     1.8 -{
     1.9 -	name = "Benchmarks",
    1.10 -	author = "AlliedModders LLC",
    1.11 -	description = "Basic benchmarks",
    1.12 -	version = "1.0.0.0",
    1.13 -	url = "http://www.sourcemod.net/"
    1.14 -};
    1.15 -
    1.16 -#define MATH_INT_LOOPS		2000
    1.17 -#define MATH_FLOAT_LOOPS	2000
    1.18 -#define STRING_OP_LOOPS		2000
    1.19 -#define STRING_FMT_LOOPS	2000
    1.20 -#define STRING_ML_LOOPS		2000
    1.21 -#define STRING_RPLC_LOOPS	2000
    1.22 -
    1.23 -new Float:g_dict_time
    1.24 -new Handle:g_Prof = INVALID_HANDLE
    1.25 -
    1.26 -public OnPluginStart()
    1.27 -{
    1.28 -	RegServerCmd("bench", Benchmark);
    1.29 -	g_Prof = CreateProfiler();
    1.30 -	StartProfiling(g_Prof);
    1.31 -	LoadTranslations("fakedict-sourcemod.cfg");
    1.32 -	StopProfiling(g_Prof);
    1.33 -	g_dict_time = GetProfilerTime(g_Prof);
    1.34 -}
    1.35 -
    1.36 -public Action:Benchmark(args)
    1.37 -{
    1.38 -	PrintToServer("dictionary time: %f seconds", g_dict_time);
    1.39 -	StringBench();
    1.40 -	MathBench();
    1.41 -	return Plugin_Handled;
    1.42 -}
    1.43 -
    1.44 -MathBench()
    1.45 -{
    1.46 -	StartProfiling(g_Prof);
    1.47 -	new iter = MATH_INT_LOOPS;
    1.48 -	new a, b, c;
    1.49 -	while(iter--)
    1.50 -	{
    1.51 -		a = iter * 7;
    1.52 -		b = 5 + iter;
    1.53 -		c = 6 / (iter + 3);
    1.54 -		a = 6 * (iter);
    1.55 -		b = a * 185;
    1.56 -		a = b / 25;
    1.57 -		c = b - a + 3;
    1.58 -		b = b*b;
    1.59 -		a = (a + c) / (b - c);
    1.60 -		b = 6;
    1.61 -		c = 1;
    1.62 -		b = a * 128 - c;
    1.63 -		c = b * (a + 16) * b;
    1.64 -		if (!a)
    1.65 -		{
    1.66 -			a = 5;
    1.67 -		}
    1.68 -		a = c + (28/a) - c;
    1.69 -	}
    1.70 -	StopProfiling(g_Prof);
    1.71 -	PrintToServer("int benchmark: %f seconds", GetProfilerTime(g_Prof));
    1.72 -
    1.73 -	StartProfiling(g_Prof);	
    1.74 -	new Float:fa, Float:fb, Float:fc
    1.75 -	new int1
    1.76 -	iter = MATH_FLOAT_LOOPS;
    1.77 -	while (iter--)
    1.78 -	{
    1.79 -		fa = iter * 0.7;
    1.80 -		fb = 5.1 + iter;
    1.81 -		fc = 6.1 / (float(iter) + 2.5);
    1.82 -		fa = 6.1 * (iter);
    1.83 -		fb = fa * 185.26;
    1.84 -		fa = fb / 25.56;
    1.85 -		fc = fb - a + float(3);
    1.86 -		fb = fb*fb;
    1.87 -		fa = (fa + fc) / (fb - fc);
    1.88 -		fb = 6.2;
    1.89 -		fc = float(1);
    1.90 -		int1 = RoundToNearest(fa);
    1.91 -		fb = fa * float(128) - int1;
    1.92 -		fc = fb * (a + 16.85) * float(RoundToCeil(fb));
    1.93 -		if (fa == 0.0)
    1.94 -		{
    1.95 -			fa = 5.0;
    1.96 -		}
    1.97 -		fa = fc + (float(28)/fa) - RoundToFloor(fc);
    1.98 -	}
    1.99 -	StopProfiling(g_Prof);
   1.100 -	PrintToServer("float benchmark: %f seconds", GetProfilerTime(g_Prof));
   1.101 -}
   1.102 -
   1.103 -#define KEY1	"LVWANBAGVXSXUGB"
   1.104 -#define KEY2	"IDYCVNWEOWNND"
   1.105 -#define KEY3	"UZWTRNHY"
   1.106 -#define KEY4	"EPRHAFCIUOIG"
   1.107 -#define KEY5	"RMZCVWIEY"
   1.108 -#define KEY6	"ZHPU"
   1.109 -
   1.110 -StringBench()
   1.111 -{
   1.112 -	new i = STRING_FMT_LOOPS;
   1.113 -	new String:buffer[255];
   1.114 -	
   1.115 -	StartProfiling(g_Prof);
   1.116 -	new end
   1.117 -	while (i--)
   1.118 -	{
   1.119 -		end = 0;
   1.120 -		Format(buffer, sizeof(buffer), "%d", i);
   1.121 -		Format(buffer, sizeof(buffer), "%d %s %d %f %d %-3.4s %s", i, "gaben", 30, 10.0, 20, "hello", "What a gaben");
   1.122 -		end = Format(buffer, sizeof(buffer), "Well, that's just %-17.18s!", "what.  this isn't a valid string! wait it is");
   1.123 -		end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
   1.124 -		end += Format(buffer[end], sizeof(buffer)-end, "There are %d in this %d", i, end);
   1.125 -	}
   1.126 -	StopProfiling(g_Prof);
   1.127 -	PrintToServer("format() benchmark: %f seconds", GetProfilerTime(g_Prof));
   1.128 -	
   1.129 -	StartProfiling(g_Prof);
   1.130 -	i = STRING_ML_LOOPS;
   1.131 -	new String:fmtbuf[2048];	/* don't change to decl, amxmodx doesn't use it */
   1.132 -	while (i--)
   1.133 -	{
   1.134 -		Format(fmtbuf, 2047, "%T %T %d %s %f %T", KEY1, LANG_SERVER, KEY2, LANG_SERVER, 50, "what the", 50.0, KEY3, LANG_SERVER);
   1.135 -		Format(fmtbuf, 2047, "%s %T %s %T %T", "gaben", KEY4, LANG_SERVER, "what TIME is it", KEY5, LANG_SERVER, KEY6, LANG_SERVER);
   1.136 -	}
   1.137 -	StopProfiling(g_Prof);
   1.138 -	PrintToServer("ml benchmark: %f seconds", GetProfilerTime(g_Prof));
   1.139 -	
   1.140 -	StartProfiling(g_Prof);
   1.141 -	i = STRING_OP_LOOPS;
   1.142 -	while (i--)
   1.143 -	{
   1.144 -		StringToInt(fmtbuf)
   1.145 -	}
   1.146 -	StopProfiling(g_Prof);
   1.147 -	PrintToServer("str benchmark: %f seconds", GetProfilerTime(g_Prof));
   1.148 -	
   1.149 -	StartProfiling(g_Prof);
   1.150 -	i = STRING_RPLC_LOOPS;
   1.151 -	while (i--)
   1.152 -	{
   1.153 -		strcopy(fmtbuf, 2047, "This is a test string for you.");
   1.154 -		ReplaceString(fmtbuf, sizeof(fmtbuf), " ", "ASDF")
   1.155 -		ReplaceString(fmtbuf, sizeof(fmtbuf), "SDF", "")
   1.156 -		ReplaceString(fmtbuf, sizeof(fmtbuf), "string", "gnirts")
   1.157 -	}
   1.158 -	StopProfiling(g_Prof);
   1.159 -	PrintToServer("replace benchmark: %f seconds", GetProfilerTime(g_Prof));
   1.160 -}