1
0

Benchfib.deploy.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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,$3,$5,$4,$2,$6;
  40. size=(8190);
  41. $1=self;
  42. $2=(function(iter){
  43. return smalltalk.withContext(function($ctx2) { count=(0);
  44. count;
  45. flags=_st((smalltalk.Array || Array))._new();
  46. flags;
  47. _st(size)._timesRepeat_((function(){
  48. return smalltalk.withContext(function($ctx3) { return _st(flags)._add_(true);
  49. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  50. $3=size;
  51. $4=(function(i){
  52. return smalltalk.withContext(function($ctx3) { $5=_st(flags)._at_(i);
  53. if(smalltalk.assert($5)){
  54. prime=_st(i).__plus((1));
  55. prime;
  56. k=_st(i).__plus(prime);
  57. k;
  58. _st((function(){
  59. return smalltalk.withContext(function($ctx4) { return _st(k).__lt_eq(size);
  60. }, function($ctx4) {$ctx4.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  61. return smalltalk.withContext(function($ctx4) { _st(flags)._at_put_(k,false);
  62. k=_st(k).__plus(prime);
  63. return k;
  64. }, function($ctx4) {$ctx4.fillBlock({},$ctx1)})}));
  65. count=_st(count).__plus((1));
  66. return count;
  67. };
  68. }, function($ctx3) {$ctx3.fillBlock({i:i},$ctx1)})});
  69. return _st((1))._to_do_($3,$4);
  70. }, function($ctx2) {$ctx2.fillBlock({iter:iter},$ctx1)})});
  71. _st((1))._to_do_($1,$2);
  72. $6=count;
  73. return $6;
  74. }, function($ctx1) {$ctx1.fill(self,"benchmark",{size:size,flags:flags,prime:prime,k:k,count:count}, smalltalk.Number)})},
  75. messageSends: ["to:do:", "new", "timesRepeat:", "add:", "ifTrue:", "+", "whileTrue:", "at:put:", "<=", "at:"]}),
  76. smalltalk.Number);
  77. smalltalk.addMethod(
  78. "_jsbenchFib",
  79. smalltalk.method({
  80. selector: "jsbenchFib",
  81. fn: function (){
  82. var self=this;
  83. return smalltalk.withContext(function($ctx1) { if (this < 2) {
  84. return 1;
  85. } else {
  86. return (this-1)._jsbenchFib() + (this-2)._jsbenchFib() + 1;};
  87. return self}, function($ctx1) {$ctx1.fill(self,"jsbenchFib",{}, smalltalk.Number)})},
  88. messageSends: []}),
  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. return self}, function($ctx1) {$ctx1.fill(self,"jsbenchmark",{}, smalltalk.Number)})},
  119. messageSends: []}),
  120. smalltalk.Number);
  121. smalltalk.addMethod(
  122. "_jstinyBenchmarks",
  123. smalltalk.method({
  124. selector: "jstinyBenchmarks",
  125. fn: function (){
  126. var self=this;
  127. var t1,t2,r,n1,n2;
  128. return smalltalk.withContext(function($ctx1) { var $1;
  129. n1=(1);
  130. _st((function(){
  131. return smalltalk.withContext(function($ctx2) { t1=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  132. return smalltalk.withContext(function($ctx3) { return _st(n1)._jsbenchmark();
  133. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  134. t1;
  135. return _st(t1).__lt((1000));
  136. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  137. return smalltalk.withContext(function($ctx2) { n1=_st(n1).__star((2));
  138. return n1;
  139. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  140. n2=(28);
  141. _st((function(){
  142. return smalltalk.withContext(function($ctx2) { t2=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  143. return smalltalk.withContext(function($ctx3) { r=_st(n2)._jsbenchFib();
  144. return r;
  145. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  146. t2;
  147. return _st(t2).__lt((1000));
  148. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  149. return smalltalk.withContext(function($ctx2) { n2=_st(n2).__plus((1));
  150. return n2;
  151. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  152. $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");
  153. return $1;
  154. }, function($ctx1) {$ctx1.fill(self,"jstinyBenchmarks",{t1:t1,t2:t2,r:r,n1:n1,n2:n2}, smalltalk.Number)})},
  155. messageSends: ["whileTrue:", "*", "millisecondsToRun:", "jsbenchmark", "<", "+", "jsbenchFib", ",", "printString", "/"]}),
  156. smalltalk.Number);
  157. smalltalk.addMethod(
  158. "_tinyBenchmarks",
  159. smalltalk.method({
  160. selector: "tinyBenchmarks",
  161. fn: function (){
  162. var self=this;
  163. var t1,t2,r,n1,n2;
  164. return smalltalk.withContext(function($ctx1) { var $1;
  165. n1=(1);
  166. _st((function(){
  167. return smalltalk.withContext(function($ctx2) { t1=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  168. return smalltalk.withContext(function($ctx3) { return _st(n1)._benchmark();
  169. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  170. t1;
  171. return _st(t1).__lt((1000));
  172. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  173. return smalltalk.withContext(function($ctx2) { n1=_st(n1).__star((2));
  174. return n1;
  175. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  176. n2=(16);
  177. _st((function(){
  178. return smalltalk.withContext(function($ctx2) { t2=_st((smalltalk.Date || Date))._millisecondsToRun_((function(){
  179. return smalltalk.withContext(function($ctx3) { r=_st(n2)._benchFib();
  180. return r;
  181. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  182. t2;
  183. return _st(t2).__lt((1000));
  184. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  185. return smalltalk.withContext(function($ctx2) { n2=_st(n2).__plus((1));
  186. return n2;
  187. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  188. $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");
  189. return $1;
  190. }, function($ctx1) {$ctx1.fill(self,"tinyBenchmarks",{t1:t1,t2:t2,r:r,n1:n1,n2:n2}, smalltalk.Number)})},
  191. messageSends: ["whileTrue:", "*", "millisecondsToRun:", "benchmark", "<", "+", "benchFib", ",", "printString", "/"]}),
  192. smalltalk.Number);