Benchfib.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. define("amber/legacy/Benchfib", ["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. $core.addPackage('Benchfib');
  4. $core.packages["Benchfib"].innerEval = function (expr) { return eval(expr); };
  5. $core.packages["Benchfib"].transport = {"type":"amd","amdNamespace":"amber/legacy"};
  6. $core.addClass('Benchfib', $globals.Object, [], 'Benchfib');
  7. $core.addMethod(
  8. $core.method({
  9. selector: "main",
  10. protocol: 'not yet classified',
  11. fn: function (){
  12. var self=this;
  13. var result;
  14. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  15. return $core.withContext(function($ctx1) {
  16. //>>excludeEnd("ctx");
  17. result=(0)._tinyBenchmarks();
  18. $recv(console)._log_("0 tinyBenchmarks => ".__comma(result));
  19. return self;
  20. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  21. }, function($ctx1) {$ctx1.fill(self,"main",{result:result},$globals.Benchfib.klass)});
  22. //>>excludeEnd("ctx");
  23. },
  24. //>>excludeStart("ide", pragmas.excludeIdeData);
  25. args: [],
  26. source: "main\x0a\x0a\x09| result |\x0a\x09result := 0 tinyBenchmarks.\x0a\x09console log: '0 tinyBenchmarks => ' , result",
  27. referencedClasses: [],
  28. //>>excludeEnd("ide");
  29. messageSends: ["tinyBenchmarks", "log:", ","]
  30. }),
  31. $globals.Benchfib.klass);
  32. $core.addMethod(
  33. $core.method({
  34. selector: "benchFib",
  35. protocol: '*Benchfib',
  36. fn: function (){
  37. var self=this;
  38. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  39. return $core.withContext(function($ctx1) {
  40. //>>excludeEnd("ctx");
  41. var $1,$4,$3,$2;
  42. $1=self.__lt((2));
  43. if($core.assert($1)){
  44. return (1);
  45. } else {
  46. $4=self.__minus((1));
  47. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  48. $ctx1.sendIdx["-"]=1;
  49. //>>excludeEnd("ctx");
  50. $3=$recv($4)._benchFib();
  51. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  52. $ctx1.sendIdx["benchFib"]=1;
  53. //>>excludeEnd("ctx");
  54. $2=$recv($3).__plus($recv(self.__minus((2)))._benchFib());
  55. return $recv($2).__plus((1));
  56. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  57. $ctx1.sendIdx["+"]=1;
  58. //>>excludeEnd("ctx");
  59. };
  60. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  61. }, function($ctx1) {$ctx1.fill(self,"benchFib",{},$globals.Number)});
  62. //>>excludeEnd("ctx");
  63. },
  64. //>>excludeStart("ide", pragmas.excludeIdeData);
  65. args: [],
  66. source: "benchFib\x0a\x09\x22Handy send-heavy benchmark\x22\x0a\x09\x22(result // seconds to run) = approx calls per second\x22\x0a\x09\x22\x09| r t |\x0a\x09\x09t := Time millisecondsToRun: [r := 26 benchFib].\x0a\x09\x09(r * 1000) // t\x22\x0a\x09\x22138000 on a Mac 8100/100\x22\x0a\x09^ self < 2\x0a\x09\x09ifTrue: [1]\x0a\x09\x09ifFalse: [(self-1) benchFib + (self-2) benchFib + 1]",
  67. referencedClasses: [],
  68. //>>excludeEnd("ide");
  69. messageSends: ["ifTrue:ifFalse:", "<", "+", "benchFib", "-"]
  70. }),
  71. $globals.Number);
  72. $core.addMethod(
  73. $core.method({
  74. selector: "benchmark",
  75. protocol: '*Benchfib',
  76. fn: function (){
  77. var self=this;
  78. var size,flags,prime,k,count;
  79. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  80. return $core.withContext(function($ctx1) {
  81. //>>excludeEnd("ctx");
  82. var $1;
  83. size=(8190);
  84. (1)._to_do_(self,(function(iter){
  85. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  86. return $core.withContext(function($ctx2) {
  87. //>>excludeEnd("ctx");
  88. count=(0);
  89. count;
  90. flags=$recv($globals.Array)._new();
  91. flags;
  92. $recv(size)._timesRepeat_((function(){
  93. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  94. return $core.withContext(function($ctx3) {
  95. //>>excludeEnd("ctx");
  96. return $recv(flags)._add_(true);
  97. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  98. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  99. //>>excludeEnd("ctx");
  100. }));
  101. return (1)._to_do_(size,(function(i){
  102. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  103. return $core.withContext(function($ctx3) {
  104. //>>excludeEnd("ctx");
  105. $1=$recv(flags)._at_(i);
  106. if($core.assert($1)){
  107. prime=$recv(i).__plus((1));
  108. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  109. $ctx3.sendIdx["+"]=1;
  110. //>>excludeEnd("ctx");
  111. prime;
  112. k=$recv(i).__plus(prime);
  113. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  114. $ctx3.sendIdx["+"]=2;
  115. //>>excludeEnd("ctx");
  116. k;
  117. $recv((function(){
  118. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  119. return $core.withContext(function($ctx4) {
  120. //>>excludeEnd("ctx");
  121. return $recv(k).__lt_eq(size);
  122. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  123. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,5)});
  124. //>>excludeEnd("ctx");
  125. }))._whileTrue_((function(){
  126. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  127. return $core.withContext(function($ctx4) {
  128. //>>excludeEnd("ctx");
  129. $recv(flags)._at_put_(k,false);
  130. k=$recv(k).__plus(prime);
  131. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  132. $ctx4.sendIdx["+"]=3;
  133. //>>excludeEnd("ctx");
  134. return k;
  135. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  136. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,6)});
  137. //>>excludeEnd("ctx");
  138. }));
  139. count=$recv(count).__plus((1));
  140. return count;
  141. };
  142. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  143. }, function($ctx3) {$ctx3.fillBlock({i:i},$ctx2,3)});
  144. //>>excludeEnd("ctx");
  145. }));
  146. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  147. }, function($ctx2) {$ctx2.fillBlock({iter:iter},$ctx1,1)});
  148. //>>excludeEnd("ctx");
  149. }));
  150. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  151. $ctx1.sendIdx["to:do:"]=1;
  152. //>>excludeEnd("ctx");
  153. return count;
  154. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  155. }, function($ctx1) {$ctx1.fill(self,"benchmark",{size:size,flags:flags,prime:prime,k:k,count:count},$globals.Number)});
  156. //>>excludeEnd("ctx");
  157. },
  158. //>>excludeStart("ide", pragmas.excludeIdeData);
  159. args: [],
  160. source: "benchmark\x0a\x09\x22Handy bytecode-heavy benchmark\x22\x0a\x09\x22(500000 // time to run) = approx bytecodes per second\x22\x0a\x09\x225000000 // (Time millisecondsToRun: [10 benchmark]) * 1000\x22\x0a\x09\x223059000 on a Mac 8100/100\x22\x0a\x09| size flags prime k count |\x0a\x09size := 8190.\x0a\x091 to: self do:\x0a\x09\x09[:iter |\x0a\x09\x09count := 0.\x0a\x09\x09flags := Array new.\x0a\x09\x09size timesRepeat: [ flags add: true].\x0a\x09\x091 to: size do:\x0a\x09\x09\x09[:i | (flags at: i) ifTrue:\x0a\x09\x09\x09\x09[prime := i+1.\x0a\x09\x09\x09\x09k := i + prime.\x0a\x09\x09\x09\x09[k <= size] whileTrue:\x0a\x09\x09\x09\x09\x09[flags at: k put: false.\x0a\x09\x09\x09\x09\x09k := k + prime].\x0a\x09\x09\x09\x09count := count + 1]]].\x0a\x09^ count",
  161. referencedClasses: ["Array"],
  162. //>>excludeEnd("ide");
  163. messageSends: ["to:do:", "new", "timesRepeat:", "add:", "ifTrue:", "at:", "+", "whileTrue:", "<=", "at:put:"]
  164. }),
  165. $globals.Number);
  166. $core.addMethod(
  167. $core.method({
  168. selector: "jsbenchFib",
  169. protocol: '*Benchfib',
  170. fn: function (){
  171. var self=this;
  172. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  173. return $core.withContext(function($ctx1) {
  174. //>>excludeEnd("ctx");
  175. if (this < 2) {
  176. return 1;
  177. } else {
  178. return (this-1)._jsbenchFib() + (this-2)._jsbenchFib() + 1;};
  179. return self;
  180. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  181. }, function($ctx1) {$ctx1.fill(self,"jsbenchFib",{},$globals.Number)});
  182. //>>excludeEnd("ctx");
  183. },
  184. //>>excludeStart("ide", pragmas.excludeIdeData);
  185. args: [],
  186. source: "jsbenchFib\x0a\x0a\x09<if (this < 2) {\x0areturn 1;\x0a} else {\x0areturn (this-1)._jsbenchFib() + (this-2)._jsbenchFib() + 1;}>",
  187. referencedClasses: [],
  188. //>>excludeEnd("ide");
  189. messageSends: []
  190. }),
  191. $globals.Number);
  192. $core.addMethod(
  193. $core.method({
  194. selector: "jsbenchmark",
  195. protocol: '*Benchfib',
  196. fn: function (){
  197. var self=this;
  198. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  199. return $core.withContext(function($ctx1) {
  200. //>>excludeEnd("ctx");
  201. var size = 8190;
  202. var count;
  203. for (var z=0;z<this;z++) {
  204. count = 0;
  205. var flags = new Array();
  206. for (var p=0; p<size; p++) {
  207. flags[p] = true;
  208. }
  209. for (var i=1;i<=size;i++) {
  210. if (flags[i-1]) {
  211. var prime = i+1;
  212. var k = i + prime;
  213. while (k <= size) {
  214. flags[k-1] = false;
  215. k = k + prime;
  216. }
  217. count = count + 1;
  218. }
  219. }
  220. }
  221. return count;
  222. return self;
  223. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  224. }, function($ctx1) {$ctx1.fill(self,"jsbenchmark",{},$globals.Number)});
  225. //>>excludeEnd("ctx");
  226. },
  227. //>>excludeStart("ide", pragmas.excludeIdeData);
  228. args: [],
  229. source: "jsbenchmark\x0a\x0a<\x0avar size = 8190;\x0avar count;\x0afor (var z=0;z<this;z++) {\x0a\x09count = 0;\x0a\x09var flags = new Array();\x0a\x09for (var p=0; p<size; p++) {\x0a\x09flags[p] = true;\x0a\x09}\x0a\x09for (var i=1;i<=size;i++) {\x0a\x09\x09if (flags[i-1]) {\x0a\x09\x09\x09var prime = i+1;\x0a\x09\x09\x09var k = i + prime;\x0a\x09\x09\x09while (k <= size) {\x0a\x09\x09\x09\x09flags[k-1] = false;\x0a\x09\x09\x09\x09k = k + prime;\x0a\x09\x09\x09}\x0a\x09\x09\x09count = count + 1;\x0a\x09\x09}\x0a\x09}\x0a}\x0areturn count>",
  230. referencedClasses: [],
  231. //>>excludeEnd("ide");
  232. messageSends: []
  233. }),
  234. $globals.Number);
  235. $core.addMethod(
  236. $core.method({
  237. selector: "jstinyBenchmarks",
  238. protocol: '*Benchfib',
  239. fn: function (){
  240. var self=this;
  241. var t1,t2,r,n1,n2;
  242. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  243. return $core.withContext(function($ctx1) {
  244. //>>excludeEnd("ctx");
  245. var $7,$6,$5,$4,$3,$2,$1;
  246. n1=(1);
  247. $recv((function(){
  248. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  249. return $core.withContext(function($ctx2) {
  250. //>>excludeEnd("ctx");
  251. t1=$recv($globals.Date)._millisecondsToRun_((function(){
  252. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  253. return $core.withContext(function($ctx3) {
  254. //>>excludeEnd("ctx");
  255. return $recv(n1)._jsbenchmark();
  256. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  257. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  258. //>>excludeEnd("ctx");
  259. }));
  260. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  261. $ctx2.sendIdx["millisecondsToRun:"]=1;
  262. //>>excludeEnd("ctx");
  263. t1;
  264. return $recv(t1).__lt((1000));
  265. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  266. $ctx2.sendIdx["<"]=1;
  267. //>>excludeEnd("ctx");
  268. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  269. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  270. //>>excludeEnd("ctx");
  271. }))._whileTrue_((function(){
  272. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  273. return $core.withContext(function($ctx2) {
  274. //>>excludeEnd("ctx");
  275. n1=$recv(n1).__star((2));
  276. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  277. $ctx2.sendIdx["*"]=1;
  278. //>>excludeEnd("ctx");
  279. return n1;
  280. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  281. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  282. //>>excludeEnd("ctx");
  283. }));
  284. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  285. $ctx1.sendIdx["whileTrue:"]=1;
  286. //>>excludeEnd("ctx");
  287. n2=(28);
  288. $recv((function(){
  289. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  290. return $core.withContext(function($ctx2) {
  291. //>>excludeEnd("ctx");
  292. t2=$recv($globals.Date)._millisecondsToRun_((function(){
  293. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  294. return $core.withContext(function($ctx3) {
  295. //>>excludeEnd("ctx");
  296. r=$recv(n2)._jsbenchFib();
  297. return r;
  298. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  299. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,5)});
  300. //>>excludeEnd("ctx");
  301. }));
  302. t2;
  303. return $recv(t2).__lt((1000));
  304. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  305. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,4)});
  306. //>>excludeEnd("ctx");
  307. }))._whileTrue_((function(){
  308. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  309. return $core.withContext(function($ctx2) {
  310. //>>excludeEnd("ctx");
  311. n2=$recv(n2).__plus((1));
  312. return n2;
  313. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  314. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,6)});
  315. //>>excludeEnd("ctx");
  316. }));
  317. $7=$recv(n1).__star((500000));
  318. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  319. $ctx1.sendIdx["*"]=3;
  320. //>>excludeEnd("ctx");
  321. $6=$recv($7).__star((1000));
  322. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  323. $ctx1.sendIdx["*"]=2;
  324. //>>excludeEnd("ctx");
  325. $5=$recv($6).__slash(t1);
  326. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  327. $ctx1.sendIdx["/"]=1;
  328. //>>excludeEnd("ctx");
  329. $4=$recv($5)._printString();
  330. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  331. $ctx1.sendIdx["printString"]=1;
  332. //>>excludeEnd("ctx");
  333. $3=$recv($4).__comma(" bytecodes/sec; ");
  334. $2=$recv($3).__comma($recv($recv($recv(r).__star((1000))).__slash(t2))._printString());
  335. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  336. $ctx1.sendIdx[","]=2;
  337. //>>excludeEnd("ctx");
  338. $1=$recv($2).__comma(" sends/sec");
  339. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  340. $ctx1.sendIdx[","]=1;
  341. //>>excludeEnd("ctx");
  342. return $1;
  343. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  344. }, function($ctx1) {$ctx1.fill(self,"jstinyBenchmarks",{t1:t1,t2:t2,r:r,n1:n1,n2:n2},$globals.Number)});
  345. //>>excludeEnd("ctx");
  346. },
  347. //>>excludeStart("ide", pragmas.excludeIdeData);
  348. args: [],
  349. source: "jstinyBenchmarks\x0a\x09\x220 jstinyBenchmarks\x22\x0a\x0a\x09| t1 t2 r n1 n2 |\x0a\x09n1 := 1.\x0a\x09[t1 := Date millisecondsToRun: [n1 jsbenchmark].\x0a\x09t1 < 1000] whileTrue:[n1 := n1 * 2]. \x22Note: #benchmark's runtime is about O(n)\x22\x0a\x0a\x09n2 := 28.\x0a\x09[t2 := Date millisecondsToRun: [r := n2 jsbenchFib].\x0a\x09t2 < 1000] whileTrue:[n2 := n2 + 1].\x0a\x09\x22Note: #jsbenchFib's runtime is about O(k^n),\x0a\x09\x09where k is the golden number = (1 + 5 sqrt) / 2 = 1.618....\x22\x0a\x0a\x09^ ((n1 * 500000 * 1000) / t1) printString, ' bytecodes/sec; ',\x0a\x09\x09((r * 1000) / t2) printString, ' sends/sec'",
  350. referencedClasses: ["Date"],
  351. //>>excludeEnd("ide");
  352. messageSends: ["whileTrue:", "millisecondsToRun:", "jsbenchmark", "<", "*", "jsbenchFib", "+", ",", "printString", "/"]
  353. }),
  354. $globals.Number);
  355. $core.addMethod(
  356. $core.method({
  357. selector: "tinyBenchmarks",
  358. protocol: '*Benchfib',
  359. fn: function (){
  360. var self=this;
  361. var t1,t2,r,n1,n2;
  362. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  363. return $core.withContext(function($ctx1) {
  364. //>>excludeEnd("ctx");
  365. var $7,$6,$5,$4,$3,$2,$1;
  366. n1=(1);
  367. $recv((function(){
  368. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  369. return $core.withContext(function($ctx2) {
  370. //>>excludeEnd("ctx");
  371. t1=$recv($globals.Date)._millisecondsToRun_((function(){
  372. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  373. return $core.withContext(function($ctx3) {
  374. //>>excludeEnd("ctx");
  375. return $recv(n1)._benchmark();
  376. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  377. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
  378. //>>excludeEnd("ctx");
  379. }));
  380. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  381. $ctx2.sendIdx["millisecondsToRun:"]=1;
  382. //>>excludeEnd("ctx");
  383. t1;
  384. return $recv(t1).__lt((1000));
  385. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  386. $ctx2.sendIdx["<"]=1;
  387. //>>excludeEnd("ctx");
  388. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  389. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  390. //>>excludeEnd("ctx");
  391. }))._whileTrue_((function(){
  392. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  393. return $core.withContext(function($ctx2) {
  394. //>>excludeEnd("ctx");
  395. n1=$recv(n1).__star((2));
  396. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  397. $ctx2.sendIdx["*"]=1;
  398. //>>excludeEnd("ctx");
  399. return n1;
  400. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  401. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)});
  402. //>>excludeEnd("ctx");
  403. }));
  404. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  405. $ctx1.sendIdx["whileTrue:"]=1;
  406. //>>excludeEnd("ctx");
  407. n2=(16);
  408. $recv((function(){
  409. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  410. return $core.withContext(function($ctx2) {
  411. //>>excludeEnd("ctx");
  412. t2=$recv($globals.Date)._millisecondsToRun_((function(){
  413. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  414. return $core.withContext(function($ctx3) {
  415. //>>excludeEnd("ctx");
  416. r=$recv(n2)._benchFib();
  417. return r;
  418. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  419. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,5)});
  420. //>>excludeEnd("ctx");
  421. }));
  422. t2;
  423. return $recv(t2).__lt((1000));
  424. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  425. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,4)});
  426. //>>excludeEnd("ctx");
  427. }))._whileTrue_((function(){
  428. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  429. return $core.withContext(function($ctx2) {
  430. //>>excludeEnd("ctx");
  431. n2=$recv(n2).__plus((1));
  432. return n2;
  433. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  434. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,6)});
  435. //>>excludeEnd("ctx");
  436. }));
  437. $7=$recv(n1).__star((500000));
  438. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  439. $ctx1.sendIdx["*"]=3;
  440. //>>excludeEnd("ctx");
  441. $6=$recv($7).__star((1000));
  442. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  443. $ctx1.sendIdx["*"]=2;
  444. //>>excludeEnd("ctx");
  445. $5=$recv($6).__slash(t1);
  446. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  447. $ctx1.sendIdx["/"]=1;
  448. //>>excludeEnd("ctx");
  449. $4=$recv($5)._printString();
  450. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  451. $ctx1.sendIdx["printString"]=1;
  452. //>>excludeEnd("ctx");
  453. $3=$recv($4).__comma(" bytecodes/sec; ");
  454. $2=$recv($3).__comma($recv($recv($recv(r).__star((1000))).__slash(t2))._printString());
  455. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  456. $ctx1.sendIdx[","]=2;
  457. //>>excludeEnd("ctx");
  458. $1=$recv($2).__comma(" sends/sec");
  459. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  460. $ctx1.sendIdx[","]=1;
  461. //>>excludeEnd("ctx");
  462. return $1;
  463. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  464. }, function($ctx1) {$ctx1.fill(self,"tinyBenchmarks",{t1:t1,t2:t2,r:r,n1:n1,n2:n2},$globals.Number)});
  465. //>>excludeEnd("ctx");
  466. },
  467. //>>excludeStart("ide", pragmas.excludeIdeData);
  468. args: [],
  469. source: "tinyBenchmarks\x0a\x09\x22Report the results of running the two tiny Squeak benchmarks.\x0a\x09ar 9/10/1999: Adjusted to run at least 1 sec to get more stable results\x22\x0a\x09\x220 tinyBenchmarks\x22\x0a\x09\x22On a 292 MHz G3 Mac: 22727272 bytecodes/sec; 984169 sends/sec\x22\x0a\x09\x22On a 400 MHz PII/Win98: 18028169 bytecodes/sec; 1081272 sends/sec\x22\x0a\x09| t1 t2 r n1 n2 |\x0a\x09n1 := 1.\x0a\x09[t1 := Date millisecondsToRun: [n1 benchmark].\x0a\x09t1 < 1000] whileTrue:[n1 := n1 * 2]. \x22Note: #benchmark's runtime is about O(n)\x22\x0a\x0a\x09n2 := 16.\x0a\x09[t2 := Date millisecondsToRun: [r := n2 benchFib].\x0a\x09t2 < 1000] whileTrue:[n2 := n2 + 1].\x0a\x09\x22Note: #benchFib's runtime is about O(k^n),\x0a\x09\x09where k is the golden number = (1 + 5 sqrt) / 2 = 1.618....\x22\x0a\x0a\x09^ ((n1 * 500000 * 1000) / t1) printString, ' bytecodes/sec; ',\x0a\x09\x09((r * 1000) / t2) printString, ' sends/sec'",
  470. referencedClasses: ["Date"],
  471. //>>excludeEnd("ide");
  472. messageSends: ["whileTrue:", "millisecondsToRun:", "benchmark", "<", "*", "benchFib", "+", ",", "printString", "/"]
  473. }),
  474. $globals.Number);
  475. });