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.

198 lines
6.0 KiB

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