PHP код:
// Profiler v1.1 (copyright (c) 2014-2015 Daniel_Cortez) \\ Pro-Pawn.ru
// Условия использования данного кода: http://pro-pawn.ru/showthread.php?12585
/*Настройки.*/
#include <a_samp>
//==============================================================================
new forveh_vehicles[MAX_VEHICLES];
new forveh_count = 0;
#if !defined IsValidVehicle
native IsValidVehicle(vehicleid);
#endif
#define forveh(%0) for(new ouf, %0=forveh_vehicles[ouf]; ouf<forveh_count; %0=forveh_vehicles[++ouf])
stock Forveh_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay, addsiren=0)
{
new vehid = CreateVehicle(modelid, x, y, z,angle, color1, color2, respawn_delay, addsiren);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_CreateVehicle
#undef CreateVehicle
#else
#define _ALS_CreateVehicle
#endif
#define CreateVehicle Forveh_CreateVehicle
stock Forveh_AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
{
new vehid = AddStaticVehicle(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_AddStaticVehicle
#undef AddStaticVehicle
#else
#define _ALS_AddStaticVehicle
#endif
#define AddStaticVehicle Forveh_AddStaticVehicle
stock Forveh_AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay, addsiren=0)
{
new vehid = AddStaticVehicleEx(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2,respawn_delay, addsiren);
forveh_vehicles[forveh_count++]=vehid;
return vehid;
}
#if defined _ALS_AddStaticVehicleEx
#undef AddStaticVehicleEx
#else
#define _ALS_AddStaticVehicleEx
#endif
#define AddStaticVehicleEx Forveh_AddStaticVehicleEx
stock Forveh_DestroyVehicle(vehicleid)
{
if(!IsValidVehicle(vehicleid)) return 0;
for(new i=0;i<forveh_count;i++)
{
if(forveh_vehicles[i]==vehicleid)
{
forveh_vehicles[i]=forveh_vehicles[--forveh_count];
break;
}
}
return DestroyVehicle(vehicleid);
}
#if defined _ALS_DestroyVehicle
#undef DestroyVehicle
#else
#define _ALS_DestroyVehicle
#endif
#define DestroyVehicle Forveh_DestroyVehicle
//==============================================================================
#include "../include/dc_foreach_veh.inc"
const PROFILE_VEHICLES_COUNT = MAX_VEHICLES;
const PROFILE_ITERATIONS_MAJOR = 1_000_000;
const PROFILE_ITERATIONS_MINOR = 10;
new const code_snippets_names[2][] =
{
{"forveh(c)"},
{"foreach(v:Vehicle)"}
};
#define Prerequisites();\
printf("Кол-во транспорта: %d.", PROFILE_VEHICLES_COUNT);\
new v;\
for (i = 0; i < PROFILE_VEHICLES_COUNT; ++i)\
CreateVehicle(411, 0.0, 0.0, 0.0, 0.0, 0, 0, -1, false);
#define CodeSnippet1();\
forveh(c){}
#define CodeSnippet2();\
foreach (v:Vehicle){}
/*Конец настроек.*/
#tryinclude <a_samp>
#if defined _samp_included
#define LINE_BREAK ""
#else
#define LINE_BREAK "\n"
#include <core>
#include <time>
#define GetTickCount() tickcount()
#endif
new code_snippets_time[sizeof(code_snippets_names)] = {0, ...};
main()
{
new t1, t2, i, j;
#emit zero.pri
#emit lctrl 7
#emit stor.s.pri i
printf(
"Тестирование: <%s> vs <%s>" LINE_BREAK,
code_snippets_names[0], code_snippets_names[1]
);
static const JIT_status_strings[2][] = {"интерпретируемый", "с JIT-компиляцией"};
printf(
"Режим: %s, %dx%d итераций.\a" LINE_BREAK,
JIT_status_strings[i],
PROFILE_ITERATIONS_MAJOR, PROFILE_ITERATIONS_MINOR
);
Prerequisites();
for (i = 0; i < PROFILE_ITERATIONS_MAJOR; ++i)
{
t1 = GetTickCount();
for (j = 0; j < PROFILE_ITERATIONS_MINOR; ++j)
{
CodeSnippet1();
}
t1 = GetTickCount()-t1;
#if !defined _samp_included
if(t1 < 0)
continue;
#endif
t2 = GetTickCount();
for (j = 0; j < PROFILE_ITERATIONS_MINOR; ++j)
{
CodeSnippet2();
}
t2 = GetTickCount()-t2;
#if !defined _samp_included
if(t2 < 0)
continue;
#endif
code_snippets_time[0] += t1;
code_snippets_time[1] += t2;
}
for (i = 0; i < sizeof(code_snippets_names); ++i)
printf(
"%s: %d" LINE_BREAK,
code_snippets_names[i], code_snippets_time[i]
);
print("\a\a" LINE_BREAK);
}