05.07.2016, 23:13
(
Last edited by Gammix; 12/06/2018 at 03:50 PM.
)
dini2.inc
Updated: v3.1 (10 March, 201
Improved version of "dini.inc" with high performance and same syntax!
INI is mostly used for initializing data to your server. But i have seen many gamemodes/filterscripts still use this old library which is very slow/inefficient in today's time, so i though of making an improved version.Updated: v3.1 (10 March, 201
Improved version of "dini.inc" with high performance and same syntax!
How this works?
Well it works with arrays. The files' data is read once when you use any "Set" function of dini. A timer starts which will free the memory of that file later after 'n' milliseconds. So unlike original dini, this one don't open and close a file everytime we use a Set/Get function. It works exactly like SII but with the ability to operate multiple files at a time.
Benchmark
Quote:
* Dini2.inc Writing 100 files with 64 fields, 3 times takes: 333 ms Reading 100 files with 64 fields, 3 times takes: 132 ms * Dini.inc (old version) Writing 100 files with 64 fields, 3 times takes: 36485 ms Reading 100 files with 64 fields, 3 times takes: 1835 ms |
Benchmark Source-Code
You can use this code to perform tests with other INI processors to compare results!
How to compare results with original Dini.inc and Dini2.inc?
First compile the script with "#include <Dini2.inc>" and then run the samp-server.exe.
Second test, replace "#include <Dini2.inc>" to "#include <Dini.inc>" and compile. Run samp-server.exe.
You have result for both. Dini is way way slower than new one. Don't run test on 500 files for Dini.inc, it will hang up or you have to wait for hours to get results lol!
PHP Code:
#include <a_samp>
#include <Dini2>
main() {
const ITERATIONS = 3;
const NUM_FILES = 100;
const NUM_FIELDS = 64;
new s, e;
new fileName[54];
new fieldName[64];
// START
s = GetTickCount();
//
for (new a; a < ITERATIONS; a++) {
for (new b; b < NUM_FILES; b++) {
format(fileName, sizeof fileName, "file_%i.ini", b);
#if !defined dini2_included
dini_Create(fileName);
#endif
for (new c; c < NUM_FIELDS; c++) {
format(fieldName, sizeof fieldName, "field_%i", c);
dini_Set(fileName, fieldName, "value");
}
}
}
#if defined dini2_included
for (new a; a < NUM_FILES; a++) {
format(fileName, sizeof fileName, "file_%i.ini", a);
dini_Timeout(fileName);
}
#endif
//
e = GetTickCount();
printf("Writing %i files with %i fields, %i times takes: %i ms", NUM_FILES, NUM_FIELDS, ITERATIONS, (e - s));
// END
// START
s = GetTickCount();
//
for (new a; a < ITERATIONS; a++) {
for (new b; b < NUM_FILES; b++) {
format(fileName, sizeof fileName, "file_%i.ini", b);
#if !defined dini2_included
dini_Create(fileName);
#endif
for (new c; c < NUM_FIELDS; c++) {
format(fieldName, sizeof fieldName, "field_%i", c);
dini_Get(fileName, fieldName);
}
}
}
#if defined dini2_included
for (new a; a < NUM_FILES; a++) {
format(fileName, sizeof fileName, "file_%i.ini", a);
dini_Timeout(fileName);
}
#endif
//
e = GetTickCount();
printf("Reading %i files with %i fields, %i times takes: %i ms", NUM_FILES, NUM_FIELDS, ITERATIONS, (e - s));
// END
for (new a; a < NUM_FILES; a++) {
format(fileName, sizeof fileName, "file_%i.ini", a);
dini_Remove(fileName);
}
}
PHP Code:
dini_Exists(const filename[]);
dini_Remove(const filename[]);
dini_Create(const filename[]);
dini_Set(const filename[], const key[], const value[]);
dini_IntSet(const filename[], const key[], value);
dini_FloatSet(const filename[], const key[], Float:value);
dini_BoolSet(const filename[], const key[], bool:value);
dini_Get(const filename[], const key[]);
dini_Int(const filename[], const key[]);
Float:dini_Float(const filename[], const key[]);
bool:dini_Bool(const filename[], const key[]);
dini_Unset(const filename[], const key[]);
dini_Isset(const filename[], const key[]);
DINI_StripNewLine(const string[]);
DINI_fcopytextfile(const filename[], const newfilename[]);
// New function from v1.0+
dini_Timeout(const filename[]);
// New functions from v3.0+
dini_NumKeys(const filename[]);
dini_GetKeyName(const filename[], keyid);
// New function from v3.1+
DINI_frenametextfile(const filename[], const newfilename[]);
https://github.com/Agneese-Saini/SA-...lude/dini2.inc