added GetSysTickCount for benchmarking
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40892
This commit is contained in:
parent
13493fd7d5
commit
1b6b0f6c5e
@ -18,8 +18,15 @@
|
||||
#include "PluginSys.h"
|
||||
#include "HandleSys.h"
|
||||
|
||||
HandleType_t g_PlIter;
|
||||
#if defined PLATFORM_WINDOWS
|
||||
#include <windows.h>
|
||||
#elif defined PLATFORM_LINUX
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
|
||||
HandleType_t g_PlIter;
|
||||
|
||||
class CoreNativeHelpers :
|
||||
public SMGlobalClass,
|
||||
@ -257,12 +264,32 @@ static cell_t SetFailState(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeErrorEx(SP_ERROR_ABORTED, "%s", str);
|
||||
}
|
||||
|
||||
static cell_t GetSysTickCount(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
#if defined PLATFORM_WINDOWS
|
||||
return (cell_t)GetTickCount();
|
||||
#elif defined PLATFORM_LINUX
|
||||
tms tm;
|
||||
clock_t ticks = times(&tm);
|
||||
long ticks_per_sec = sysconf(_SC_CLK_TCK);
|
||||
double ftcks = (double)ticks / (double)ticks_per_sec;
|
||||
fticks *= 1000.0f;
|
||||
if (fticks > INT_MAX)
|
||||
{
|
||||
double r = (int)(fticks / INT_MAX) * (double)INT_MAX;
|
||||
fticks -= r;
|
||||
}
|
||||
return (cell_t)fticks;
|
||||
#endif
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(coreNatives)
|
||||
{
|
||||
{"GetPluginFilename", GetPluginFilename},
|
||||
{"GetPluginInfo", GetPluginInfo},
|
||||
{"GetPluginIterator", GetPluginIterator},
|
||||
{"GetPluginStatus", GetPluginStatus},
|
||||
{"GetSysTickCount", GetSysTickCount},
|
||||
{"GetTime", GetTime},
|
||||
{"IsPluginDebugging", IsPluginDebugging},
|
||||
{"MorePlugins", MorePlugins},
|
||||
|
@ -285,5 +285,14 @@ native GameConfGetOffset(Handle:gc, const String:key[]);
|
||||
*/
|
||||
native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
|
||||
|
||||
/**
|
||||
* Returns the operating system's "tick count," which is a number of
|
||||
* milliseconds since the operating system loaded. This can be used
|
||||
* for basic benchmarks.
|
||||
*
|
||||
* @return Tick count in milliseconds.
|
||||
*/
|
||||
native GetSysTickCount();
|
||||
|
||||
#include <helpers>
|
||||
#include <entity>
|
||||
|
Loading…
Reference in New Issue
Block a user