1
0

Benchfib.deploy.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. smalltalk.addPackage('Benchfib', {});
  2. smalltalk.addClass('Benchfib', smalltalk.Object, [], 'Benchfib');
  3. smalltalk.addMethod(
  4. "_main",
  5. smalltalk.method({
  6. selector: "main",
  7. fn: function (){
  8. var self=this;
  9. var result;
  10. result=smalltalk.send((0),"_tinyBenchmarks",[]);
  11. smalltalk.send(console,"_log_",[smalltalk.send("0 tinyBenchmarks => ","__comma",[result])]);
  12. return self}
  13. }),
  14. smalltalk.Benchfib.klass);
  15. smalltalk.addMethod(
  16. "_benchFib",
  17. smalltalk.method({
  18. selector: "benchFib",
  19. fn: function (){
  20. var self=this;
  21. var $2,$1;
  22. $2=smalltalk.send(self,"__lt",[(2)]);
  23. if(smalltalk.assert($2)){
  24. $1=(1);
  25. } else {
  26. $1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"__minus",[(1)]),"_benchFib",[]),"__plus",[smalltalk.send(smalltalk.send(self,"__minus",[(2)]),"_benchFib",[])]),"__plus",[(1)]);
  27. };
  28. return $1;
  29. }
  30. }),
  31. smalltalk.Number);
  32. smalltalk.addMethod(
  33. "_benchmark",
  34. smalltalk.method({
  35. selector: "benchmark",
  36. fn: function (){
  37. var self=this;
  38. var $1;
  39. var size;
  40. var flags;
  41. var prime;
  42. var k;
  43. var count;
  44. size=(8190);
  45. smalltalk.send((1),"_to_do_",[self,(function(iter){
  46. count=(0);
  47. count;
  48. flags=smalltalk.send((smalltalk.Array || Array),"_new",[]);
  49. flags;
  50. smalltalk.send(size,"_timesRepeat_",[(function(){
  51. return smalltalk.send(flags,"_add_",[true]);
  52. })]);
  53. return smalltalk.send((1),"_to_do_",[size,(function(i){
  54. $1=smalltalk.send(flags,"_at_",[i]);
  55. if(smalltalk.assert($1)){
  56. prime=smalltalk.send(i,"__plus",[(1)]);
  57. prime;
  58. k=smalltalk.send(i,"__plus",[prime]);
  59. k;
  60. smalltalk.send((function(){
  61. return smalltalk.send(k,"__lt_eq",[size]);
  62. }),"_whileTrue_",[(function(){
  63. smalltalk.send(flags,"_at_put_",[k,false]);
  64. k=smalltalk.send(k,"__plus",[prime]);
  65. return k;
  66. })]);
  67. count=smalltalk.send(count,"__plus",[(1)]);
  68. return count;
  69. };
  70. })]);
  71. })]);
  72. return count;
  73. }
  74. }),
  75. smalltalk.Number);
  76. smalltalk.addMethod(
  77. "_jsbenchFib",
  78. smalltalk.method({
  79. selector: "jsbenchFib",
  80. fn: function (){
  81. var self=this;
  82. if (this < 2) {
  83. return 1;
  84. } else {
  85. return (this-1)._jsbenchFib() + (this-2)._jsbenchFib() + 1;};
  86. ;
  87. return self}
  88. }),
  89. smalltalk.Number);
  90. smalltalk.addMethod(
  91. "_jsbenchmark",
  92. smalltalk.method({
  93. selector: "jsbenchmark",
  94. fn: function (){
  95. var self=this;
  96. var size = 8190;
  97. var count;
  98. for (var z=0;z<this;z++) {
  99. count = 0;
  100. var flags = new Array();
  101. for (var p=0; p<size; p++) {
  102. flags[p] = true;
  103. }
  104. for (var i=1;i<=size;i++) {
  105. if (flags[i-1]) {
  106. var prime = i+1;
  107. var k = i + prime;
  108. while (k <= size) {
  109. flags[k-1] = false;
  110. k = k + prime;
  111. }
  112. count = count + 1;
  113. }
  114. }
  115. }
  116. return count;
  117. ;
  118. return self}
  119. }),
  120. smalltalk.Number);
  121. smalltalk.addMethod(
  122. "_jstinyBenchmarks",
  123. smalltalk.method({
  124. selector: "jstinyBenchmarks",
  125. fn: function (){
  126. var self=this;
  127. var $1;
  128. var t1;
  129. var t2;
  130. var r;
  131. var n1;
  132. var n2;
  133. n1=(1);
  134. smalltalk.send((function(){
  135. t1=smalltalk.send((smalltalk.Date || Date),"_millisecondsToRun_",[(function(){
  136. return smalltalk.send(n1,"_jsbenchmark",[]);
  137. })]);
  138. t1;
  139. return smalltalk.send(t1,"__lt",[(1000)]);
  140. }),"_whileTrue_",[(function(){
  141. n1=smalltalk.send(n1,"__star",[(2)]);
  142. return n1;
  143. })]);
  144. n2=(28);
  145. smalltalk.send((function(){
  146. t2=smalltalk.send((smalltalk.Date || Date),"_millisecondsToRun_",[(function(){
  147. r=smalltalk.send(n2,"_jsbenchFib",[]);
  148. return r;
  149. })]);
  150. t2;
  151. return smalltalk.send(t2,"__lt",[(1000)]);
  152. }),"_whileTrue_",[(function(){
  153. n2=smalltalk.send(n2,"__plus",[(1)]);
  154. return n2;
  155. })]);
  156. $1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(n1,"__star",[(500000)]),"__star",[(1000)]),"__slash",[t1]),"_printString",[]),"__comma",[" bytecodes/sec; "]),"__comma",[smalltalk.send(smalltalk.send(smalltalk.send(r,"__star",[(1000)]),"__slash",[t2]),"_printString",[])]),"__comma",[" sends/sec"]);
  157. return $1;
  158. }
  159. }),
  160. smalltalk.Number);
  161. smalltalk.addMethod(
  162. "_tinyBenchmarks",
  163. smalltalk.method({
  164. selector: "tinyBenchmarks",
  165. fn: function (){
  166. var self=this;
  167. var $1;
  168. var t1;
  169. var t2;
  170. var r;
  171. var n1;
  172. var n2;
  173. n1=(1);
  174. smalltalk.send((function(){
  175. t1=smalltalk.send((smalltalk.Date || Date),"_millisecondsToRun_",[(function(){
  176. return smalltalk.send(n1,"_benchmark",[]);
  177. })]);
  178. t1;
  179. return smalltalk.send(t1,"__lt",[(1000)]);
  180. }),"_whileTrue_",[(function(){
  181. n1=smalltalk.send(n1,"__star",[(2)]);
  182. return n1;
  183. })]);
  184. n2=(16);
  185. smalltalk.send((function(){
  186. t2=smalltalk.send((smalltalk.Date || Date),"_millisecondsToRun_",[(function(){
  187. r=smalltalk.send(n2,"_benchFib",[]);
  188. return r;
  189. })]);
  190. t2;
  191. return smalltalk.send(t2,"__lt",[(1000)]);
  192. }),"_whileTrue_",[(function(){
  193. n2=smalltalk.send(n2,"__plus",[(1)]);
  194. return n2;
  195. })]);
  196. $1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(n1,"__star",[(500000)]),"__star",[(1000)]),"__slash",[t1]),"_printString",[]),"__comma",[" bytecodes/sec; "]),"__comma",[smalltalk.send(smalltalk.send(smalltalk.send(r,"__star",[(1000)]),"__slash",[t2]),"_printString",[])]),"__comma",[" sends/sec"]);
  197. return $1;
  198. }
  199. }),
  200. smalltalk.Number);