SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Includes (https://forum.sa-mp.com/forumdisplay.php?f=83)
-   -   [Include] dini2.inc - Improved dini file processor with amazing benchmarks (aka. gini)! (https://forum.sa-mp.com/showthread.php?t=611399)

Gammix 05/07/2016 11:13 PM

dini2.inc - Improved dini file processor with amazing performance (aka. gini)!
 
dini2.inc
Updated: v3.1 (10 March, 2018)
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.

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
Its like saving 100 players data 3 times all at once (64 fields each file)!

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 
se;

    new 
fileName[54];
    new 
fieldName[64];

    
// START
    
GetTickCount();
    
//

    
for (new aITERATIONSa++) {
        for (new 
bNUM_FILESb++) {
            
format(fileNamesizeof fileName"file_%i.ini"b);
            
#if !defined dini2_included
            
dini_Create(fileName);
            
#endif
            
            
for (new cNUM_FIELDSc++) {
                
format(fieldNamesizeof fieldName"field_%i"c);
                
dini_Set(fileNamefieldName"value");
            }
        }
    }

    
#if defined dini2_included
    
for (new aNUM_FILESa++) {
        
format(fileNamesizeof fileName"file_%i.ini"a);
        
dini_Timeout(fileName);
    }
    
#endif

    //
    
GetTickCount();
    
printf("Writing %i files with %i fields, %i times takes: %i ms"NUM_FILESNUM_FIELDSITERATIONS, (s));
    
// END



    // START
    
GetTickCount();
    
//

    
for (new aITERATIONSa++) {
        for (new 
bNUM_FILESb++) {
            
format(fileNamesizeof fileName"file_%i.ini"b);
            
#if !defined dini2_included
            
dini_Create(fileName);
            
#endif
            
            
for (new cNUM_FIELDSc++) {
                
format(fieldNamesizeof fieldName"field_%i"c);
                
dini_Get(fileNamefieldName);
            }
        }
    }

    
#if defined dini2_included
    
for (new aNUM_FILESa++) {
        
format(fileNamesizeof fileName"file_%i.ini"a);
        
dini_Timeout(fileName);
    }
    
#endif

    //
    
GetTickCount();
    
printf("Reading %i files with %i fields, %i times takes: %i ms"NUM_FILESNUM_FIELDSITERATIONS, (s));
    
// END



    
for (new aNUM_FILESa++) {
        
format(fileNamesizeof fileName"file_%i.ini"a);
        
dini_Remove(fileName);
    }


Functions
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[]); 

Download
https://github.com/Agneese-Saini/SA-...lude/dini2.inc

Dayvison_ 06/07/2016 12:59 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Any bench?
I suggest you put suport for sections ^^
Good work ^^

Gammix 06/07/2016 01:12 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Quote:

Originally Posted by Day_ (Post 3729160)
Any bench?

The way this works is pretty different, if you benchmark functions, they will be like "1ms" for 1000 iterations or even more. Because the operation of writing the file is done in a timer which gets executed after defined seconds.

I'll try to make up some by editing the include; probably by using 2ms for timer's interval.

Quote:

Originally Posted by Day_ (Post 3729160)
I suggest you put suport for sections ^^

What do you mean ?

Uberanwar 06/07/2016 01:19 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Wow Gammix, you've made a lot of contributions to the community! Keep up the good work man.
:) +rep

Shady 06/07/2016 02:26 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Amazing, man. I did a test on my server and found out that GINI is faster than Y_INI and DINI.

Edit: On another script (NGRP), I got some errors. Mind if help ya?
pawn Code:
./includess/commands.pwn(23306) : error 017: undefined symbol "dini_Exists"
./includess/mysql.pwn(5653) : error 017: undefined symbol "dini_Create"
./includess/mysql.pwn(5654) : error 017: undefined symbol "dini_Remove"
./includess/mysql.pwn(5655) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5656) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5657) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5658) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5659) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5660) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5661) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5662) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5663) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5664) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(6) : error 017: undefined symbol "dini_Exists"
./includess/OnPlayerLoad.pwn(8) : error 017: undefined symbol "dini_Create"
./includess/OnPlayerLoad.pwn(9) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(10) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(11) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(12) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(13) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(14) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(15) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(16) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(17) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(18) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(19) : error 017: undefined symbol "dini_IntSet"

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


26 Errors.

Gammix 06/07/2016 03:02 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Quote:

Originally Posted by ShadyEG (Post 3729183)
Amazing, man. I did a test on my server and found out that GINI is faster than Y_INI and DINI.

Edit: On another script (NGRP), I got some errors. Mind if help ya?
pawn Code:
./includess/commands.pwn(23306) : error 017: undefined symbol "dini_Exists"
./includess/mysql.pwn(5653) : error 017: undefined symbol "dini_Create"
./includess/mysql.pwn(5654) : error 017: undefined symbol "dini_Remove"
./includess/mysql.pwn(5655) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5656) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5657) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5658) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5659) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5660) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5661) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5662) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5663) : error 017: undefined symbol "dini_IntSet"
./includess/mysql.pwn(5664) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(6) : error 017: undefined symbol "dini_Exists"
./includess/OnPlayerLoad.pwn(8) : error 017: undefined symbol "dini_Create"
./includess/OnPlayerLoad.pwn(9) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(10) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(11) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(12) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(13) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(14) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(15) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(16) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(17) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(18) : error 017: undefined symbol "dini_IntSet"
./includess/OnPlayerLoad.pwn(19) : error 017: undefined symbol "dini_IntSet"

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


26 Errors.

v1.1.1 creates all DINI functions when INI_CONVERT_DINI is defined. Checkout the thread once again for instructions.

Shady 06/07/2016 03:11 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Updated again to v1.1.2 due to another bug in the new conversation.

WhiteGhost 06/07/2016 03:36 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Quote:

Originally Posted by Uberanwar (Post 3729168)
Wow Gammix, you've made a lot of contributions to the community! Keep up the good work man.
:) +rep

Ikr imagine if he were to have a server it would be awesome.
Anyways GoodJob You got my rep even before this.

Gammix 06/07/2016 03:54 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Thanks all.

I realized most of the scripts use INI as a database and taking that in mind, we cannot execute so many timers at once (max is maybe 30). So in next update, i'll use on global timer to run and work on tick counts.

SystemX 06/07/2016 04:11 AM

Re: gini.inc - Fast multi file processor with "dini's" syntax
 
Amazing as always budd'
+repp


All times are GMT. The time now is 01:01 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.