Advertisement
EnzoMetlc

[Inclide] Numeric combinations - Benchmarks.

Dec 10th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. public OnFilterScriptInit()
  4. {
  5. new a, b, i, var, set, get;
  6.  
  7. set = get = 0;
  8. /* Konstantinos */
  9. // Set
  10. a = GetTickCount();
  11. for(i = 0; i < 100000; i++) SetCombination(var, 0, 0);
  12. b = GetTickCount();
  13. set += b - a;
  14.  
  15. a = GetTickCount();
  16. for(i = 0; i < 100000; i++) SetCombination(var, 0, 0);
  17. b = GetTickCount();
  18. set += b - a;
  19.  
  20. a = GetTickCount();
  21. for(i = 0; i < 100000; i++) SetCombination(var, 0, 0);
  22. b = GetTickCount();
  23. set += b - a;
  24. printf("* [Set] Konstantinos - %i ms", set / 3);
  25.  
  26. // Get
  27. a = GetTickCount();
  28. for(i = 0; i < 100000; i++) GetCombination(var, 0);
  29. b = GetTickCount();
  30. get += b - a;
  31.  
  32. a = GetTickCount();
  33. for(i = 0; i < 100000; i++) GetCombination(var, 0);
  34. b = GetTickCount();
  35. get += b - a;
  36.  
  37. a = GetTickCount();
  38. for(i = 0; i < 100000; i++) GetCombination(var, 0);
  39. b = GetTickCount();
  40. get += b - a;
  41. printf("* [Get] Konstantinos - %i ms", get / 3);
  42.  
  43.  
  44. /* Swedky */
  45. set = get = 0;
  46. // Set
  47. a = GetTickCount();
  48. for(i = 0; i < 100000; i++) SetCombination2(var, 0, 0);
  49. b = GetTickCount();
  50. set += b - a;
  51.  
  52. a = GetTickCount();
  53. for(i = 0; i < 100000; i++) SetCombination2(var, 0, 0);
  54. b = GetTickCount();
  55. set += b - a;
  56.  
  57. a = GetTickCount();
  58. for(i = 0; i < 100000; i++) SetCombination2(var, 0, 0);
  59. b = GetTickCount();
  60. set += b - a;
  61. printf("* [Set] Swedky - %i ms", set / 3);
  62.  
  63. // Get
  64. a = GetTickCount();
  65. for(i = 0; i < 100000; i++) GetCombination2(var, 0);
  66. b = GetTickCount();
  67. get += b - a;
  68.  
  69. a = GetTickCount();
  70. for(i = 0; i < 100000; i++) GetCombination2(var, 0);
  71. b = GetTickCount();
  72. get += b - a;
  73.  
  74. a = GetTickCount();
  75. for(i = 0; i < 100000; i++) GetCombination2(var, 0);
  76. b = GetTickCount();
  77. get += b - a;
  78. printf("* [Get] Swedky - %i ms", get / 3);
  79. return 1;
  80. }
  81.  
  82.  
  83.  
  84.  
  85. stock SetCombination(&var, slot, value)
  86. {
  87. new comb[11];
  88. format(comb, 11, "%010i", var);
  89. comb[9 - slot] = (1 <= value <= 9) ? 48 + value : 48;
  90. var = strval(comb);
  91. return 1;
  92. }
  93.  
  94. stock GetCombination(var, slot)
  95. {
  96. new comb[11];
  97. format(comb, 11, "%010i", var);
  98. if(48 <= (slot = comb[9 - slot]) <= 57) return slot - 48;
  99. return 0;
  100. }
  101.  
  102.  
  103. stock SetCombination2(&var, slot, value) // ~0.0035 ms
  104. {
  105. new comb[11];
  106. format(comb, 11, "%010i", var);
  107.  
  108. switch(value)
  109. {
  110. case 1: comb[9 - slot] = '1';
  111. case 2: comb[9 - slot] = '2';
  112. case 3: comb[9 - slot] = '3';
  113. case 4: comb[9 - slot] = '4';
  114. case 5: comb[9 - slot] = '5';
  115. case 6: comb[9 - slot] = '6';
  116. case 7: comb[9 - slot] = '7';
  117. case 8: comb[9 - slot] = '8';
  118. case 9: comb[9 - slot] = '9';
  119. default: comb[9 - slot] = '0';
  120. }
  121.  
  122. var = strval(comb);
  123. return 1;
  124. }
  125.  
  126. stock GetCombination2(var, slot) // ~0.002 ms
  127. {
  128. new comb[11];
  129. format(comb, 11, "%010i", var);
  130. switch(comb[9 - slot])
  131. {
  132. case '0': return 0;
  133. case '1': return 1;
  134. case '2': return 2;
  135. case '3': return 3;
  136. case '4': return 4;
  137. case '5': return 5;
  138. case '6': return 6;
  139. case '7': return 7;
  140. case '8': return 8;
  141. case '9': return 9;
  142. }
  143. return 0;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement