Advertisement
Kyosaur

MySQL vs SQLite (SA-MP forums)

Jul 14th, 2011
1,347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.89 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. #define ITER_COUNT          100
  5. #define MYSQL_TEST_THREAD   4
  6.  
  7. new
  8.     DB:g_Sqlite,
  9.     DBResult:g_Res,
  10.     g_Str[128],
  11.     g_Ticks[2];
  12.    
  13.    
  14. main(){}
  15.  
  16. public OnGameModeInit()
  17. {
  18. //------------------------- sqlite---------------------------------------------
  19.  
  20.     print("SQLite test starting...");
  21.     g_Sqlite = db_open("Test.SQLITE");
  22.    
  23.     //Insert
  24.     g_Ticks[0] = GetTickCount();
  25.    
  26.     for(new i = 0; i < ITER_COUNT; i++)
  27.     {
  28.         db_free_result(db_query(g_Sqlite, "INSERT INTO `Test` VALUES('STRRRRRRRRRRRRIIIIIIIIIIIIIIIIIIING TEEEEEEEEEST', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)"));
  29.        
  30.     }
  31.     g_Ticks[1] = GetTickCount();
  32.  
  33.     printf("SQLite Insert: %d queries in %d ms", ITER_COUNT, g_Ticks[1]-g_Ticks[0]);
  34.    
  35.    
  36.     //Select
  37.  
  38.     g_Ticks[0] = GetTickCount();
  39.  
  40.     for(new i = 0; i < ITER_COUNT; i++)
  41.     {
  42.         g_Res = db_query(g_Sqlite, "SELECT `String` FROM `Test` LIMIT 1");
  43.         db_get_field_assoc(g_Res,"String",g_Str, sizeof(g_Str));
  44.         db_free_result(g_Res);
  45.     }
  46.  
  47.     g_Ticks[1] = GetTickCount();
  48.  
  49.     printf("SQLite Select: %d queries in %d ms", ITER_COUNT, g_Ticks[1]-g_Ticks[0]);
  50.     printf(" >> SQLite Last select result: %s",g_Str);
  51.    
  52.     //update
  53.    
  54.     g_Ticks[0] = GetTickCount();
  55.  
  56.     for(new i = 0; i < ITER_COUNT; i++)
  57.     {
  58.         db_free_result(db_query(g_Sqlite, "Update `Test` SET `String` = 'newstring'"));
  59.     }
  60.  
  61.     g_Ticks[1] = GetTickCount();
  62.  
  63.     printf("SQLite Update: %d queries in %d ms", ITER_COUNT, g_Ticks[1]-g_Ticks[0]);
  64.    
  65.     db_close(g_Sqlite);
  66.    
  67.    
  68. //------------------------- Mysql ------------------------------------------------
  69.  
  70.     print("MySQL test starting....");
  71.    
  72.     //insert
  73.     mysql_connect("localhost", "root", "SAMP", "Kyolovestacos8");
  74.     g_Ticks[0] = GetTickCount();
  75.    
  76.     for(new i = 0; i < ITER_COUNT; i++)
  77.     {
  78.         mysql_query("INSERT INTO `Test` VALUES('STRRRRRRRRRRRRIIIIIIIIIIIIIIIIIIING TEEEEEEEEEST', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)");
  79.         mysql_store_result();  // to make it a bit fair (even though its dumb >.>)
  80.         mysql_free_result();
  81.     }
  82.    
  83.     g_Ticks[1] = GetTickCount();
  84.  
  85.     printf("MySQL Insert: %d queries in %d ms", ITER_COUNT, g_Ticks[1]-g_Ticks[0]);
  86.    
  87.     //Select
  88.    
  89.     g_Ticks[0] = GetTickCount();
  90.  
  91.     for(new i = 0; i < ITER_COUNT; i++)
  92.     {
  93.         mysql_query("SELECT `String` FROM `Test` LIMIT 1");
  94.         mysql_store_result();
  95.        
  96.         if(mysql_retrieve_row())
  97.         {
  98.             mysql_fetch_field_row(g_Str,"String");
  99.         }
  100.         mysql_free_result();
  101.     }
  102.  
  103.     g_Ticks[1] = GetTickCount();
  104.     printf("MySQL Select: %d queries in %d ms", ITER_COUNT, g_Ticks[1]-g_Ticks[0]);
  105.     printf(" >> MySQL Last select result: %s",g_Str);
  106.    
  107.     //update
  108.     g_Ticks[0] = GetTickCount();
  109.  
  110.     for(new i = 0; i < ITER_COUNT; i++)
  111.     {
  112.         mysql_query("Update `Test` SET `String` = 'newstring'");
  113.         mysql_store_result(); // once again to be a little more fair
  114.         mysql_free_result();
  115.     }
  116.  
  117.     g_Ticks[1] = GetTickCount();
  118.  
  119.     printf("MySQL Update: %d queries in %d ms", ITER_COUNT, g_Ticks[1]-g_Ticks[0]);
  120.    
  121.     mysql_close();
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement