|
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
|
08-26-2015
, 23:38
Re: Dynamic Objects and Properties
|
#3
|
I've done some profiling of the current version attached to the OP.
Here is the profiling code:
Spoiler
Code:
#include <sourcemod>
#include <dynamic>
public void OnPluginStart()
{
BenchmarkTest();
}
stock void BenchmarkTest()
{
int objectcount = 1000;
int membercount = 99; // must be a multiple of 3
PrintToServer("[SM] Preparing benchmark Test...");
Dynamic someoject;
char membernames[100][MAX_FIELDNAME_SIZE];
char buffer[MAX_FIELDNAME_SIZE];
int ival; float fval; char sval[MAX_FIELDNAME_SIZE];
// Make member names
for (int x = 0; x < membercount; x++)
{
Format(membernames[x], MAX_FIELDNAME_SIZE, "m_Field_%d", x);
}
PrintToServer("[SM] Starting Benchmark Tests...");
// Create objectcount objects with 99 fields in each
float start = GetEngineTime();
for (int i=0; i<objectcount; i++)
{
someoject = Dynamic(128);
}
PrintToServer("Created %d dynamic object(s) in %f second(s)", objectcount, GetEngineTime() - start);
start = GetEngineTime();
for (int i=0; i<objectcount; i++)
{
someoject = view_as<Dynamic>(i);
for (int x = 0; x < membercount; x++)
{
for (int p = 1; p < 4; p++)
{
if (p == 1)
{
someoject.SetInt(membernames[x], x+i+p);
x++;
}
else if (p==2)
{
someoject.SetFloat(membernames[x], float(x+i+p));
x++;
}
else if (p==3)
{
someoject.SetString(membernames[x], "Some nice string that has some data", 128);
}
}
}
}
PrintToServer("Created %d dynamic member(s) in %f second(s)", objectcount * membercount, GetEngineTime() - start);
start = GetEngineTime();
for (int i=0; i<objectcount; i++)
{
someoject = view_as<Dynamic>(i);
for (int x = 0; x < membercount; x++)
{
for (int p = 1; p < 4; p++)
{
if (p == 1)
{
someoject.GetInt(membernames[x]);
x++;
}
else if (p==2)
{
someoject.GetFloat(membernames[x]);
x++;
}
else if (p==3)
{
someoject.GetString(membernames[x], buffer, sizeof(buffer));
}
}
}
}
PrintToServer("Read %d dynamic member(s) in %f second(s)", objectcount * membercount, GetEngineTime() - start);
start = GetEngineTime();
for (int i=0; i<objectcount; i++)
{
someoject = view_as<Dynamic>(i);
for (int x = 0; x < membercount; x++)
{
for (int p = 1; p < 4; p++)
{
ival = x+i+p;
fval = float(x+i+p);
if (p == 1)
{
if (someoject.GetInt(membernames[x]) != ival)
PrintToServer("!! Member data INVALID! (Int)");
if (someoject.GetFloat(membernames[x]) != fval)
PrintToServer("!! Conversion error (Int2Float)");
someoject.GetString(membernames[x], buffer, sizeof(buffer));
IntToString(ival, sval, sizeof(sval));
if (!StrEqual(buffer, sval))
PrintToServer("!! Conversion error (Int2String)");
x++;
}
else if (p==2)
{
if (someoject.GetFloat(membernames[x]) != fval)
PrintToServer("!! Member data INVALID! (Float)");
if (someoject.GetInt(membernames[x]) != ival)
PrintToServer("!! Conversion error (FloatToInt)");
someoject.GetString(membernames[x], buffer, sizeof(buffer));
FloatToString(fval, sval, sizeof(sval));
if (!StrEqual(buffer, sval))
PrintToServer("!! Conversion error (Float2String)");
x++;
}
else if (p==3)
{
someoject.GetString(membernames[x], buffer, sizeof(buffer));
if (!StrEqual(buffer, "Some nice string that has some data"))
PrintToServer("!! Member data INVALID! (String)");
}
}
}
}
PrintToServer("Verified %d dynamic member(s) in %f second(s)", objectcount * membercount, GetEngineTime() - start);
start = GetEngineTime();
for (int i=0; i<objectcount; i++)
{
someoject = view_as<Dynamic>(i);
for (int x = 0; x < membercount; x++)
{
for (int p = 1; p < 4; p++)
{
if (p == 1)
{
someoject.SetInt(membernames[x], x+i+p);
x++;
}
else if (p==2)
{
someoject.SetFloat(membernames[x], float(x+i+p));
x++;
}
else if (p==3)
{
someoject.SetString(membernames[x], "Some nice string that has some data");
}
}
}
}
PrintToServer("Updated %d dynamic member(s) in %f second(s)", objectcount * membercount, GetEngineTime() - start);
start = GetEngineTime();
for (int i=0; i<objectcount; i++)
{
someoject = view_as<Dynamic>(i);
someoject.Dispose();
}
PrintToServer("Disposed %d dynamic object(s) in %f second(s)", objectcount, GetEngineTime() - start);
}
The outputs are below for 3 runs:
Code:
[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.003906 second(s)
Created 99000 dynamic member(s) in 1.492187 second(s)
Read 99000 dynamic member(s) in 0.527343 second(s)
Verified 99000 dynamic member(s) in 2.871093 second(s)
Updated 99000 dynamic member(s) in 0.542968 second(s)
Disposed 1000 dynamic object(s) in 0.011718 second(s)
[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.003906 second(s)
Created 99000 dynamic member(s) in 1.460937 second(s)
Read 99000 dynamic member(s) in 0.531250 second(s)
Verified 99000 dynamic member(s) in 2.839843 second(s)
Updated 99000 dynamic member(s) in 0.546875 second(s)
Disposed 1000 dynamic object(s) in 0.011718 second(s)
[SM] Starting Benchmark Tests...
Created 1000 dynamic object(s) in 0.000000 second(s)
Created 99000 dynamic member(s) in 1.492187 second(s)
Read 99000 dynamic member(s) in 0.527343 second(s)
Verified 99000 dynamic member(s) in 2.863281 second(s)
Updated 99000 dynamic member(s) in 0.546875 second(s)
Disposed 1000 dynamic object(s) in 0.011718 second(s)
__________________
Last edited by Neuro Toxin; 08-28-2015 at 04:14.
|
|
|
|