2
0

Benchfib.deploy.js 6.8 KB

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