Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
2.7 KiB

  1. // Set of benchmarks
  2. sysSetDesiredMemoryUsageHard(16 * 1024, 1);
  3. sysSetDesiredMemoryUsageSoft(sysGetDesiredMemoryUsageHard());
  4. //
  5. //
  6. // ACKERMAN
  7. //
  8. //
  9. print("*** ACKERMAN ***");
  10. global Ack = function(M, N)
  11. {
  12. if (M == 0)
  13. {
  14. N=N+1;
  15. return(N);
  16. }
  17. if (N == 0)
  18. {
  19. M=M-1;
  20. return(Ack(M, 1));
  21. }
  22. N=N-1;
  23. return (Ack(M-1, Ack(M, N)));
  24. };
  25. NUM = 8;
  26. TICK(); //GD Used to be clock() what was that matt?
  27. print(Ack(3,NUM));
  28. print("time = ", TICK());
  29. //
  30. //
  31. // FIB
  32. //
  33. //
  34. print("*** FIB ***");
  35. global fib = function(n)
  36. {
  37. if (n < 2) { return(1); }
  38. return fib(n-2) + fib(n-1);
  39. };
  40. N = 32;
  41. TICK();
  42. print(fib(N));
  43. print("time = ", TICK());
  44. //
  45. //
  46. // MATRIX
  47. //
  48. //
  49. print("*** MATRIX ***");
  50. local n = 300;
  51. local size = 30;
  52. mkmatrix = function(rows, cols)
  53. {
  54. count = 1;
  55. mx = table();
  56. for(i=0; i < rows; i=i+1)
  57. {
  58. row = table();
  59. for(j = 0; j < cols; j=j+1)
  60. {
  61. row[j] = count;
  62. count=count+1;
  63. }
  64. mx[i] = row;
  65. }
  66. return mx;
  67. };
  68. mmult = function(rows, cols, m1, m2)
  69. {
  70. m3 = table();
  71. for(i = 0; i < rows; i=i+1)
  72. {
  73. m3[i] = table();
  74. m1_i = m1[i];
  75. for(j = 0; j < cols; j=j+1)
  76. {
  77. rowj = 0;
  78. for(k = 0; k < cols; k=k+1)
  79. {
  80. rowj = rowj + m1_i[k] * m2[k][j];
  81. }
  82. m3[i][j] = rowj;
  83. }
  84. }
  85. return m3;
  86. };
  87. TICK();
  88. m1 = mkmatrix(size, size);
  89. m2 = mkmatrix(size, size);
  90. for(i = 0; i < n; i=i+1)
  91. {
  92. mm = mmult(size, size, m1, m2);
  93. }
  94. t = TICK();
  95. print(mm[0][0], mm[2][3], mm[3][2], mm[4][4]);
  96. print("time = ", t);
  97. //
  98. //
  99. // HASH
  100. //
  101. //
  102. print("*** HASH ***");
  103. local n = 80000;
  104. TICK();
  105. X=table();
  106. for(i=1; i <= n; i=i+1)
  107. {
  108. //print(format("%x", i), i);
  109. X[format("%x", i)] = i;
  110. }
  111. c = 0;
  112. for(i=n; i>=1; i=i-1)
  113. {
  114. if(X[i+""])
  115. {
  116. c=c+1;
  117. }
  118. }
  119. print(c);
  120. print("time = ", TICK());
  121. //
  122. //
  123. // HEAPSORT
  124. //
  125. //
  126. print("*** HEAPSORT ***");
  127. global IM = 139968.;
  128. global IA = 3877.;
  129. global IC = 29573.;
  130. global LAST = 42.;
  131. gen_random = function(max)
  132. {
  133. global LAST = (LAST * IA + IC) % IM;
  134. return ((max * LAST) / IM);
  135. };
  136. heapsort = function(n, ra)
  137. {
  138. l = n/2 + 1;
  139. ir = n;
  140. for(;;)
  141. {
  142. if(l > 1)
  143. {
  144. l=l-1;
  145. rra = ra[l];
  146. }
  147. else
  148. {
  149. rra = ra[ir];
  150. ra[ir] = ra[1];
  151. ir=ir-1;
  152. if(ir == 1)
  153. {
  154. ra[1] = rra;
  155. return;
  156. }
  157. }
  158. i = l;
  159. j = l * 2;
  160. while(j <= ir)
  161. {
  162. if(j < ir and ra[j] < ra[j+1])
  163. {
  164. j=j+1;
  165. }
  166. if(rra < ra[j])
  167. {
  168. ra[i] = ra[j];
  169. i = j;
  170. j = j + i;
  171. }
  172. else
  173. {
  174. j = ir + 1;
  175. }
  176. }
  177. ra[i] = rra;
  178. }
  179. };
  180. TICK();
  181. local ary = table();
  182. local N = 80000;
  183. for(i = 0; i < N; i=i+1)
  184. {
  185. ary[i] = gen_random(1.0);
  186. }
  187. heapsort(N, ary);
  188. print(ary[N-1]);
  189. print("time = ", TICK());