1
0

Benchfib.deploy.js 7.0 KB

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