2
0

Benchfib.deploy.js 6.8 KB

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