Benchfib.deploy.js 6.9 KB

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