Advertisement
GArtem

Test_mxINI_vs_SQLite_vs_MySQL_vs_ORM

Jul 14th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.52 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <mxINI>
  4.  
  5. main()
  6. {
  7.     print("\n------------TEST------------------");
  8.     print("----------------------------------\n");
  9. }
  10.  
  11. new DB:TestDB;
  12.  
  13. new mysql_connect_ID;  
  14. #define COUNT       100
  15.  
  16. enum ormTest
  17. {
  18.     ORM:ID,
  19.     id,
  20.     value,
  21. }
  22. new OrmTest[ormTest];
  23.  
  24. stock Pause() for(new i; i != 40000000; i++) {} //Примерно 1 сек
  25.  
  26. public OnGameModeInit()
  27. {
  28.     SetGameModeText("test");
  29.    
  30.     mysql_connect_ID = mysql_connect("localhost", "root", "testpawn", ""), mysql_log(LOG_DEBUG);
  31.     TestDB = db_open("test.db");
  32.     db_query (TestDB, "CREATE TABLE IF NOT EXISTS `account` (`id`   INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `value` INTEGER)");
  33.     db_query (TestDB, "PRAGMA synchronous=OFF; PRAGMA journal_mode=OFF;");
  34.     mysql_function_query(mysql_connect_ID, "CREATE TABLE IF NOT EXISTS `account` ( `id` INT NOT NULL AUTO_INCREMENT , `value` INT NOT NULL , PRIMARY KEY (`id`) ) ENGINE = InnoDB", false, "", "");
  35.     mysql_function_query(mysql_connect_ID, "CREATE TABLE IF NOT EXISTS `account2` ( `id` INT NOT NULL AUTO_INCREMENT , `value` INT NOT NULL , PRIMARY KEY (`id`) ) ENGINE = InnoDB", false, "", "");
  36.  
  37.     new testtime, string[128], file;
  38.     testtime = GetTickCount();
  39.     for (new i; i != COUNT; i++)
  40.     {
  41.         format(string, sizeof(string), "Test_%d.ini", i+1);
  42.         file = ini_createFile(string);
  43.         ini_setInteger(file, "value", i);
  44.         ini_closeFile(file);
  45.     }
  46.     printf ( "[mxINI]Создание %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  47.     testtime = GetTickCount();
  48.     for (new i; i != COUNT; i++)
  49.     {
  50.         format(string, sizeof(string), "Test_%d.ini", i+1);
  51.         file = ini_openFile(string);
  52.         ini_setInteger(file, "value", i+1);
  53.         ini_closeFile(file);
  54.     }
  55.     printf ( "[mxINI]Обновление %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  56.     testtime = GetTickCount();
  57.     for (new i; i != COUNT; i++)
  58.     {
  59.         format(string, sizeof(string), "Test_%d.ini", i+1);
  60.         fremove(string);
  61.     }
  62.     printf ( "[file]Удаление %i ms.(%i iterations)\n", GetTickCount () - testtime,  COUNT);
  63.     testtime = GetTickCount();
  64.     for (new i; i != COUNT; i++)
  65.     {
  66.         format(string, sizeof(string), "INSERT INTO `account` (`value`) VALUES ('%i')", i);  
  67.         db_query(TestDB, string);  
  68.     }
  69.     printf ( "[SQLite]Создание %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  70.     testtime = GetTickCount();
  71.     for (new i; i != COUNT; i++)
  72.     {
  73.         format(string, sizeof(string), "UPDATE `account` SET `value` = '%i' WHERE `id` = '%i'", i+50, i+1);
  74.         db_query(TestDB, string);  
  75.     }
  76.     printf ( "[SQLite]Обновление %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  77.     testtime = GetTickCount();
  78.     for (new i; i != COUNT; i++)
  79.     {
  80.         format(string, sizeof(string), "DELETE FROM `account` WHERE `id` = '%i'", i+1);
  81.         db_query(TestDB, string);  
  82.     }
  83.     printf ( "[SQLite]Удаление %i ms.(%i iterations)\n", GetTickCount () - testtime,  COUNT);
  84.     testtime = GetTickCount();
  85.     for (new i; i != COUNT; i++)
  86.     {
  87.         format(string, sizeof(string), "INSERT INTO `account` (`value`) VALUES ('%i')", i+1);  
  88.         mysql_function_query(mysql_connect_ID, string, false, "", "");
  89.     }
  90.     printf ( "[MySQL]Создание %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  91.     Pause(); //Пауза Без неё мускул не успевает обрабатывать запросы
  92.     testtime = GetTickCount();
  93.     for (new i; i != COUNT; i++)
  94.     {
  95.         format(string, sizeof(string), "UPDATE `account` SET `value` = '%i' WHERE `id` = '%i'", i+50, i+1);
  96.         mysql_function_query(mysql_connect_ID, string, false, "", "");
  97.     }
  98.     printf ( "[MySQL]Обновление %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  99.     Pause(); //Пауза Без неё мускул не успевает обрабатывать запросы
  100.     testtime = GetTickCount();
  101.     for (new i; i != COUNT; i++)
  102.     {
  103.         format(string, sizeof(string), "DELETE FROM `account` WHERE `id` = '%i'", i+1);
  104.         mysql_function_query(mysql_connect_ID, string, false, "", "");
  105.     }
  106.     printf ( "[MySQL]Удаление %i ms.(%i iterations)\n", GetTickCount () - testtime,  COUNT);
  107.     Pause(); //Пауза Без неё мускул не успевает обрабатывать запросы
  108.     testtime = GetTickCount();
  109.     OrmTest[ID] = orm_create("account2");
  110.     orm_addvar_int(OrmTest[ID], OrmTest[id], "id");
  111.     orm_addvar_int(OrmTest[ID], OrmTest[value], "value");
  112.     for (new i; i != COUNT; i++)
  113.     {
  114.         OrmTest[value] = i;
  115.         orm_insert(OrmTest[ID]);
  116.     }
  117.     printf ( "[ORM]Создание %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  118.     Pause(); //Пауза Без неё мускул не успевает обрабатывать запросы
  119.     testtime = GetTickCount();
  120.     for (new i; i != COUNT; i++)
  121.     {
  122.         OrmTest[id] = i+1;
  123.         OrmTest[value] = i+50;
  124.         orm_setkey(OrmTest[ID], "id");
  125.         orm_update(OrmTest[ID]);
  126.     }
  127.     printf ( "[ORM]Обновление %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  128.     Pause(); //Пауза Без неё мускул не успевает обрабатывать запросы
  129.     testtime = GetTickCount();
  130.     for (new i; i != COUNT; i++)
  131.     {
  132.         OrmTest[id] = i+1;
  133.         OrmTest[value] = i+50;
  134.         orm_setkey(OrmTest[ID], "id");
  135.         orm_delete(OrmTest[ID]);
  136.     }
  137.     orm_destroy(OrmTest[ID]);
  138.     printf ( "[ORM]Удаление %i ms.(%i iterations)", GetTickCount () - testtime,  COUNT);
  139.     db_close(TestDB);
  140.     return 1;
  141. }
  142.  
  143. public OnGameModeExit()
  144. {
  145.     return 1;
  146. }
  147.  
  148. public OnQueryError(errorid, error[], callback[], query[], connectionHandle)
  149. {
  150.     printf("MySQL Error: [%d]%s", errorid, error);
  151.     return 1;
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement