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