2
0

Benchfib.deploy.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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=nil;
  10. (result=smalltalk.send((0), "_tinyBenchmarks", []));
  11. smalltalk.send((typeof console == 'undefined' ? nil : console), "_log_", [smalltalk.send("0 tinyBenchmarks => ", "__comma", [result])]);
  12. return self;}
  13. }),
  14. smalltalk.Benchfib.klass);
  15. smalltalk.addMethod(
  16. "_benchFib",
  17. smalltalk.method({
  18. selector: "benchFib",
  19. fn: function (){
  20. var self=this;
  21. return ((($receiver = self < (2)).klass === smalltalk.Boolean) ? ($receiver ? (function(){return (1);})() : (function(){return ((($receiver = ((($receiver = smalltalk.send(self - (1), "_benchFib", [])).klass === smalltalk.Number) ? $receiver +smalltalk.send(self - (2), "_benchFib", []) : smalltalk.send($receiver, "__plus", [smalltalk.send(self - (2), "_benchFib", [])]))).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)]));})()) : smalltalk.send($receiver, "_ifTrue_ifFalse_", [(function(){return (1);}), (function(){return ((($receiver = ((($receiver = smalltalk.send(self - (1), "_benchFib", [])).klass === smalltalk.Number) ? $receiver +smalltalk.send(self - (2), "_benchFib", []) : smalltalk.send($receiver, "__plus", [smalltalk.send(self - (2), "_benchFib", [])]))).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)]));})]));
  22. return self;}
  23. }),
  24. smalltalk.Number);
  25. smalltalk.addMethod(
  26. "_benchmark",
  27. smalltalk.method({
  28. selector: "benchmark",
  29. fn: function (){
  30. var self=this;
  31. var size=nil;
  32. var flags=nil;
  33. var prime=nil;
  34. var k=nil;
  35. var count=nil;
  36. (size=(8190));
  37. smalltalk.send((1), "_to_do_", [self, (function(iter){(count=(0));(flags=smalltalk.send((smalltalk.Array || Array), "_new", []));smalltalk.send(size, "_timesRepeat_", [(function(){return smalltalk.send(flags, "_add_", [true]);})]);return smalltalk.send((1), "_to_do_", [size, (function(i){return ((($receiver = smalltalk.send(flags, "_at_", [i])).klass === smalltalk.Boolean) ? ($receiver ? (function(){(prime=((($receiver = i).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));(k=((($receiver = i).klass === smalltalk.Number) ? $receiver +prime : smalltalk.send($receiver, "__plus", [prime])));(function(){while((function(){return ((($receiver = k).klass === smalltalk.Number) ? $receiver <=size : smalltalk.send($receiver, "__lt_eq", [size]));})()) {(function(){smalltalk.send(flags, "_at_put_", [k, false]);return (k=((($receiver = k).klass === smalltalk.Number) ? $receiver +prime : smalltalk.send($receiver, "__plus", [prime])));})()}})();return (count=((($receiver = count).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){(prime=((($receiver = i).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));(k=((($receiver = i).klass === smalltalk.Number) ? $receiver +prime : smalltalk.send($receiver, "__plus", [prime])));(function(){while((function(){return ((($receiver = k).klass === smalltalk.Number) ? $receiver <=size : smalltalk.send($receiver, "__lt_eq", [size]));})()) {(function(){smalltalk.send(flags, "_at_put_", [k, false]);return (k=((($receiver = k).klass === smalltalk.Number) ? $receiver +prime : smalltalk.send($receiver, "__plus", [prime])));})()}})();return (count=((($receiver = count).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));})]));})]);})]);
  38. return count;
  39. return self;}
  40. }),
  41. smalltalk.Number);
  42. smalltalk.addMethod(
  43. "_jsbenchFib",
  44. smalltalk.method({
  45. selector: "jsbenchFib",
  46. fn: function (){
  47. var self=this;
  48. if (this < 2) {
  49. return 1;
  50. } else {
  51. return (this-1)._jsbenchFib() + (this-2)._jsbenchFib() + 1;};
  52. return self;}
  53. }),
  54. smalltalk.Number);
  55. smalltalk.addMethod(
  56. "_jsbenchmark",
  57. smalltalk.method({
  58. selector: "jsbenchmark",
  59. fn: function (){
  60. var self=this;
  61. var size = 8190;
  62. var count;
  63. for (var z=0;z<this;z++) {
  64. count = 0;
  65. var flags = new Array();
  66. for (var p=0; p<size; p++) {
  67. flags[p] = true;
  68. }
  69. for (var i=1;i<=size;i++) {
  70. if (flags[i-1]) {
  71. var prime = i+1;
  72. var k = i + prime;
  73. while (k <= size) {
  74. flags[k-1] = false;
  75. k = k + prime;
  76. }
  77. count = count + 1;
  78. }
  79. }
  80. }
  81. return count;
  82. return self;}
  83. }),
  84. smalltalk.Number);
  85. smalltalk.addMethod(
  86. "_jstinyBenchmarks",
  87. smalltalk.method({
  88. selector: "jstinyBenchmarks",
  89. fn: function (){
  90. var self=this;
  91. var t1=nil;
  92. var t2=nil;
  93. var r=nil;
  94. var n1=nil;
  95. var n2=nil;
  96. (n1=(1));
  97. (function(){while((function(){(t1=smalltalk.send((smalltalk.Date || Date), "_millisecondsToRun_", [(function(){return smalltalk.send(n1, "_jsbenchmark", []);})]));return ((($receiver = t1).klass === smalltalk.Number) ? $receiver <(1000) : smalltalk.send($receiver, "__lt", [(1000)]));})()) {(function(){return (n1=((($receiver = n1).klass === smalltalk.Number) ? $receiver *(2) : smalltalk.send($receiver, "__star", [(2)])));})()}})();
  98. (n2=(28));
  99. (function(){while((function(){(t2=smalltalk.send((smalltalk.Date || Date), "_millisecondsToRun_", [(function(){return (r=smalltalk.send(n2, "_jsbenchFib", []));})]));return ((($receiver = t2).klass === smalltalk.Number) ? $receiver <(1000) : smalltalk.send($receiver, "__lt", [(1000)]));})()) {(function(){return (n2=((($receiver = n2).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));})()}})();
  100. return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(((($receiver = ((($receiver = ((($receiver = n1).klass === smalltalk.Number) ? $receiver *(500000) : smalltalk.send($receiver, "__star", [(500000)]))).klass === smalltalk.Number) ? $receiver *(1000) : smalltalk.send($receiver, "__star", [(1000)]))).klass === smalltalk.Number) ? $receiver /t1 : smalltalk.send($receiver, "__slash", [t1])), "_printString", []), "__comma", [" bytecodes/sec; "]), "__comma", [smalltalk.send(((($receiver = ((($receiver = r).klass === smalltalk.Number) ? $receiver *(1000) : smalltalk.send($receiver, "__star", [(1000)]))).klass === smalltalk.Number) ? $receiver /t2 : smalltalk.send($receiver, "__slash", [t2])), "_printString", [])]), "__comma", [" sends/sec"]);
  101. return self;}
  102. }),
  103. smalltalk.Number);
  104. smalltalk.addMethod(
  105. "_tinyBenchmarks",
  106. smalltalk.method({
  107. selector: "tinyBenchmarks",
  108. fn: function (){
  109. var self=this;
  110. var t1=nil;
  111. var t2=nil;
  112. var r=nil;
  113. var n1=nil;
  114. var n2=nil;
  115. (n1=(1));
  116. (function(){while((function(){(t1=smalltalk.send((smalltalk.Date || Date), "_millisecondsToRun_", [(function(){return smalltalk.send(n1, "_benchmark", []);})]));return ((($receiver = t1).klass === smalltalk.Number) ? $receiver <(1000) : smalltalk.send($receiver, "__lt", [(1000)]));})()) {(function(){return (n1=((($receiver = n1).klass === smalltalk.Number) ? $receiver *(2) : smalltalk.send($receiver, "__star", [(2)])));})()}})();
  117. (n2=(16));
  118. (function(){while((function(){(t2=smalltalk.send((smalltalk.Date || Date), "_millisecondsToRun_", [(function(){return (r=smalltalk.send(n2, "_benchFib", []));})]));return ((($receiver = t2).klass === smalltalk.Number) ? $receiver <(1000) : smalltalk.send($receiver, "__lt", [(1000)]));})()) {(function(){return (n2=((($receiver = n2).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));})()}})();
  119. return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(((($receiver = ((($receiver = ((($receiver = n1).klass === smalltalk.Number) ? $receiver *(500000) : smalltalk.send($receiver, "__star", [(500000)]))).klass === smalltalk.Number) ? $receiver *(1000) : smalltalk.send($receiver, "__star", [(1000)]))).klass === smalltalk.Number) ? $receiver /t1 : smalltalk.send($receiver, "__slash", [t1])), "_printString", []), "__comma", [" bytecodes/sec; "]), "__comma", [smalltalk.send(((($receiver = ((($receiver = r).klass === smalltalk.Number) ? $receiver *(1000) : smalltalk.send($receiver, "__star", [(1000)]))).klass === smalltalk.Number) ? $receiver /t2 : smalltalk.send($receiver, "__slash", [t2])), "_printString", [])]), "__comma", [" sends/sec"]);
  120. return self;}
  121. }),
  122. smalltalk.Number);