You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
6.1 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. // Benchmarks from the LiDIA home page
  2. #include <cln/number.h>
  3. #include <cln/io.h>
  4. #include <cln/integer.h>
  5. #include <cln/float.h>
  6. #include <cln/float_io.h>
  7. #include <cln/real.h>
  8. #include <cln/real_io.h>
  9. #include <cln/complex.h>
  10. #include <cln/complex_io.h>
  11. #include <cstdlib>
  12. #include <cstring>
  13. #include <cln/timing.h>
  14. #include <iostream>
  15. using namespace cln;
  16. using namespace std;
  17. // Timings on Linux i486 33 MHz, 1000 decimal places = 104 32-bit words.
  18. // Function LiDIA Pari CLISP CLN
  19. // pi 0.17 / 0 0.38 / 0 0.12 / 0
  20. // gamma 7.51 / 0 -- 3.75 / 0
  21. // e 1.20 5.06 / 0.20 0.66 / 0.10
  22. // multiplication 0.018 0.010 0.010
  23. // sqrt(3) 0.051 0.012 0.01
  24. // exp(log(2)) 3.13 0.08 / 3.94 0.04
  25. // log(exp(2)) 3.07 4.93 / 2.75 1.34
  26. // sin(pi/3) 1.53 2.98 0.58
  27. // cos(pi/3) 1.59 2.16 0.58
  28. // arcsin(sqrt(3)/2) 4.24 2.22 1.26
  29. // arccos(sqrt(3)/2) 4.26 2.22 1.26
  30. // sinh(log(2)) 3.16 2.02 0.03
  31. // cosh(log(2)) 3.17 2.09 0.04
  32. // arsinh(pi) 1.93 2.62 0.65
  33. // arcosh(pi) 1.95 2.26 0.69
  34. // (Versions: Pari 1.39, clisp-1996-07-22, cln-1996-11-17.)
  35. // Timings on Solaris Sparc 20, 75 MHz, 1000 decimal places = 104 32-bit words.
  36. // Function LiDIA Pari CLISP CLN
  37. // pi 0.06 / 0 0.04 / 0 0.028 / 0
  38. // gamma 1.98 / 0 1.26 / 0 1.99 / 0
  39. // e 0 0.15 0.15
  40. // multiplication
  41. // sqrt(3) 0.0025 0.01 0.0025
  42. // exp(log(2)) 0.25 0.39 0.010
  43. // log(exp(2)) 0.21 0.39 0.31
  44. // sin(pi/3) 0.071 0.18 0.13
  45. // cos(pi/3) 0.070 0.19 0.13
  46. // arcsin(sqrt(3)/2) 0.30 0.55 0.27
  47. // arccos(sqrt(3)/2) 0.30 0.55 0.27
  48. // sinh(log(2)) 0.25 0.41 0.010
  49. // cosh(log(2)) 0.25 0.40 0.010
  50. // arsinh(pi) 0.16 0.26 0.144
  51. // arcosh(pi) 0.16 0.26 0.153
  52. // (Versions: Pari 1.39, LiDIA 1.2.1 with libI, cln-1996-10-13.)
  53. int main (int argc, char * argv[])
  54. {
  55. int repetitions = 1;
  56. if ((argc >= 3) && !strcmp(argv[1],"-r")) {
  57. repetitions = atoi(argv[2]);
  58. argc -= 2; argv += 2;
  59. }
  60. if (argc < 1)
  61. exit(1);
  62. fprint(std::cerr, "Number of repetitions: ");
  63. fprintdecimal(std::cerr, repetitions);
  64. fprint(std::cerr, "\n");
  65. float_format_t prec = float_format(1000);
  66. fprint(std::cerr, "pi\n");
  67. { cl_F p;
  68. { CL_TIMING; p = pi(prec); }
  69. { CL_TIMING;
  70. for (int rep = repetitions; rep > 0; rep--)
  71. { cl_F p = pi(prec); }
  72. }
  73. cout << p << endl << endl;
  74. }
  75. fprint(std::cerr, "gamma\n");
  76. { cl_F p;
  77. { CL_TIMING; p = eulerconst(prec); }
  78. { CL_TIMING;
  79. for (int rep = repetitions; rep > 0; rep--)
  80. { cl_F p = eulerconst(prec); }
  81. }
  82. cout << p << endl << endl;
  83. }
  84. fprint(std::cerr, "e\n");
  85. { cl_F p = exp1(prec);
  86. { CL_TIMING;
  87. for (int rep = repetitions; rep > 0; rep--)
  88. { cl_F p = exp1(prec); }
  89. }
  90. cout << p << endl << endl;
  91. }
  92. fprint(std::cerr, "sqrt(3)\n");
  93. { cl_R p = sqrt(cl_float(3,prec));
  94. { CL_TIMING;
  95. for (int rep = repetitions; rep > 0; rep--)
  96. { cl_R p = sqrt(cl_float(3,prec)); }
  97. }
  98. cout << p << endl << endl;
  99. }
  100. fprint(std::cerr, "exp(log(2))\n");
  101. { cl_N p = exp(log(cl_float(2,prec)));
  102. { CL_TIMING;
  103. for (int rep = repetitions; rep > 0; rep--)
  104. { cl_N p = exp(log(cl_float(2,prec))); }
  105. }
  106. cout << p << endl << endl;
  107. }
  108. fprint(std::cerr, "log(exp(2))\n");
  109. { cl_N p = log(exp(cl_float(2,prec)));
  110. { CL_TIMING;
  111. for (int rep = repetitions; rep > 0; rep--)
  112. { cl_N p = log(exp(cl_float(2,prec))); }
  113. }
  114. cout << p << endl << endl;
  115. }
  116. fprint(std::cerr, "sin(pi/3)\n");
  117. { cl_R p = sin(pi(prec)/3);
  118. { CL_TIMING;
  119. for (int rep = repetitions; rep > 0; rep--)
  120. { cl_R p = sin(pi(prec)/3); }
  121. }
  122. cout << p << endl << endl;
  123. }
  124. fprint(std::cerr, "cos(pi/3)\n");
  125. { cl_R p = cos(pi(prec)/3);
  126. { CL_TIMING;
  127. for (int rep = repetitions; rep > 0; rep--)
  128. { cl_R p = cos(pi(prec)/3); }
  129. }
  130. cout << p << endl << endl;
  131. }
  132. fprint(std::cerr, "arcsin(sqrt(3)/2)\n");
  133. { cl_N p = asin(sqrt(cl_float(3,prec))/2);
  134. { CL_TIMING;
  135. for (int rep = repetitions; rep > 0; rep--)
  136. { cl_N p = asin(sqrt(cl_float(3,prec))/2); }
  137. }
  138. cout << p << endl << endl;
  139. }
  140. fprint(std::cerr, "arccos(sqrt(3)/2)\n");
  141. { cl_N p = acos(sqrt(cl_float(3,prec))/2);
  142. { CL_TIMING;
  143. for (int rep = repetitions; rep > 0; rep--)
  144. { cl_N p = acos(sqrt(cl_float(3,prec))/2); }
  145. }
  146. cout << p << endl << endl;
  147. }
  148. fprint(std::cerr, "sinh(log(2))\n");
  149. { cl_N p = sinh(log(cl_float(2,prec)));
  150. { CL_TIMING;
  151. for (int rep = repetitions; rep > 0; rep--)
  152. { cl_N p = sinh(log(cl_float(2,prec))); }
  153. }
  154. cout << p << endl << endl;
  155. }
  156. fprint(std::cerr, "cosh(log(2))\n");
  157. { cl_N p = cosh(log(cl_float(2,prec)));
  158. { CL_TIMING;
  159. for (int rep = repetitions; rep > 0; rep--)
  160. { cl_N p = cosh(log(cl_float(2,prec))); }
  161. }
  162. cout << p << endl << endl;
  163. }
  164. fprint(std::cerr, "arsinh(pi)\n");
  165. { cl_N p = asinh(pi(prec));
  166. { CL_TIMING;
  167. for (int rep = repetitions; rep > 0; rep--)
  168. { cl_N p = asinh(pi(prec)); }
  169. }
  170. cout << p << endl << endl;
  171. }
  172. fprint(std::cerr, "arcosh(pi)\n");
  173. { cl_N p = acosh(pi(prec));
  174. { CL_TIMING;
  175. for (int rep = repetitions; rep > 0; rep--)
  176. { cl_N p = acosh(pi(prec)); }
  177. }
  178. cout << p << endl << endl;
  179. }
  180. }