Benchfib.deploy.js 6.4 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($ctx1) { $ctx1.result=nil;
  10. $ctx1.locals.result=_st((0))._tinyBenchmarks();
  11. _st(console)._log_(_st("0 tinyBenchmarks => ").__comma($ctx1.locals.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($ctx1) { 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($ctx1) { var $1;
  39. $ctx1.size=nil;
  40. $ctx1.flags=nil;
  41. $ctx1.prime=nil;
  42. $ctx1.k=nil;
  43. $ctx1.count=nil;
  44. $ctx1.locals.size=(8190);
  45. _st((1))._to_do_(self,(function(iter){
  46. return smalltalk.withContext(function($ctx2) { $ctx1.locals.count=(0);
  47. $ctx1.locals.count;
  48. $ctx1.locals.flags=_st((smalltalk.Array || Array))._new();
  49. $ctx1.locals.flags;
  50. _st($ctx1.locals.size)._timesRepeat_((function(){
  51. return smalltalk.withContext(function($ctx3) { return _st($ctx1.locals.flags)._add_(true);
  52. })}));
  53. return _st((1))._to_do_($ctx1.locals.size,(function(i){
  54. return smalltalk.withContext(function($ctx3) { $1=_st($ctx1.locals.flags)._at_(i);
  55. if(smalltalk.assert($1)){
  56. $ctx1.locals.prime=_st(i).__plus((1));
  57. $ctx1.locals.prime;
  58. $ctx1.locals.k=_st(i).__plus($ctx1.locals.prime);
  59. $ctx1.locals.k;
  60. _st((function(){
  61. return smalltalk.withContext(function($ctx4) { return _st($ctx1.locals.k).__lt_eq($ctx1.locals.size);
  62. })}))._whileTrue_((function(){
  63. return smalltalk.withContext(function($ctx4) { _st($ctx1.locals.flags)._at_put_($ctx1.locals.k,false);
  64. $ctx1.locals.k=_st($ctx1.locals.k).__plus($ctx1.locals.prime);
  65. return $ctx1.locals.k;
  66. })}));
  67. $ctx1.locals.count=_st($ctx1.locals.count).__plus((1));
  68. return $ctx1.locals.count;
  69. };
  70. })}));
  71. })}));
  72. return $ctx1.locals.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($ctx1) { 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($ctx1) {
  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($ctx1) { var $1;
  129. $ctx1.t1=nil;
  130. $ctx1.t2=nil;
  131. $ctx1.r=nil;
  132. $ctx1.n1=nil;
  133. $ctx1.n2=nil;
  134. $ctx1.locals.n1=(1);
  135. _st((function(){
  136. return smalltalk.withContext(function($ctx2) { $ctx1.locals.t1=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  137. return smalltalk.withContext(function($ctx3) { return _st($ctx1.locals.n1)._jsbenchmark();
  138. })}));
  139. $ctx1.locals.t1;
  140. return _st($ctx1.locals.t1).__lt((1000));
  141. })}))._whileTrue_((function(){
  142. return smalltalk.withContext(function($ctx2) { $ctx1.locals.n1=_st($ctx1.locals.n1).__star((2));
  143. return $ctx1.locals.n1;
  144. })}));
  145. $ctx1.locals.n2=(28);
  146. _st((function(){
  147. return smalltalk.withContext(function($ctx2) { $ctx1.locals.t2=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  148. return smalltalk.withContext(function($ctx3) { $ctx1.locals.r=_st($ctx1.locals.n2)._jsbenchFib();
  149. return $ctx1.locals.r;
  150. })}));
  151. $ctx1.locals.t2;
  152. return _st($ctx1.locals.t2).__lt((1000));
  153. })}))._whileTrue_((function(){
  154. return smalltalk.withContext(function($ctx2) { $ctx1.locals.n2=_st($ctx1.locals.n2).__plus((1));
  155. return $ctx1.locals.n2;
  156. })}));
  157. $1=_st(_st(_st(_st(_st(_st(_st($ctx1.locals.n1).__star((500000))).__star((1000))).__slash($ctx1.locals.t1))._printString()).__comma(" bytecodes/sec; ")).__comma(_st(_st(_st($ctx1.locals.r).__star((1000))).__slash($ctx1.locals.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($ctx1) { var $1;
  169. $ctx1.t1=nil;
  170. $ctx1.t2=nil;
  171. $ctx1.r=nil;
  172. $ctx1.n1=nil;
  173. $ctx1.n2=nil;
  174. $ctx1.locals.n1=(1);
  175. _st((function(){
  176. return smalltalk.withContext(function($ctx2) { $ctx1.locals.t1=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  177. return smalltalk.withContext(function($ctx3) { return _st($ctx1.locals.n1)._benchmark();
  178. })}));
  179. $ctx1.locals.t1;
  180. return _st($ctx1.locals.t1).__lt((1000));
  181. })}))._whileTrue_((function(){
  182. return smalltalk.withContext(function($ctx2) { $ctx1.locals.n1=_st($ctx1.locals.n1).__star((2));
  183. return $ctx1.locals.n1;
  184. })}));
  185. $ctx1.locals.n2=(16);
  186. _st((function(){
  187. return smalltalk.withContext(function($ctx2) { $ctx1.locals.t2=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  188. return smalltalk.withContext(function($ctx3) { $ctx1.locals.r=_st($ctx1.locals.n2)._benchFib();
  189. return $ctx1.locals.r;
  190. })}));
  191. $ctx1.locals.t2;
  192. return _st($ctx1.locals.t2).__lt((1000));
  193. })}))._whileTrue_((function(){
  194. return smalltalk.withContext(function($ctx2) { $ctx1.locals.n2=_st($ctx1.locals.n2).__plus((1));
  195. return $ctx1.locals.n2;
  196. })}));
  197. $1=_st(_st(_st(_st(_st(_st(_st($ctx1.locals.n1).__star((500000))).__star((1000))).__slash($ctx1.locals.t1))._printString()).__comma(" bytecodes/sec; ")).__comma(_st(_st(_st($ctx1.locals.r).__star((1000))).__slash($ctx1.locals.t2))._printString())).__comma(" sends/sec");
  198. return $1;
  199. }, self, "tinyBenchmarks", [], smalltalk.Number)}
  200. }),
  201. smalltalk.Number);