File: timebench2a.cc

package info (click to toggle)
cln 0.98-7.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 12,188 kB
  • ctags: 15,282
  • sloc: cpp: 71,545; ansic: 12,015; asm: 8,431; sh: 3,159; makefile: 886; lisp: 64
file content (80 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cl_number.h>
#include <cl_io.h>
#include <cl_integer.h>
#include <cl_float.h>
#include <cl_real.h>
#include <stdlib.h>
#include <string.h>
#include <cl_timing.h>

main (int argc, char * argv[])
{
	int digits = 100;
	int repetitions = 1;
	while (argc >= 3) {
		if (!strcmp(argv[1],"-r")) {
			repetitions = atoi(argv[2]);
			argc -= 2; argv += 2;
			continue;
		}
		if (!strcmp(argv[1],"-n")) {
			digits = atoi(argv[2]);
			argc -= 2; argv += 2;
			continue;
		}
		break;
	}
	if (argc < 1)
		exit(1);

	fprint(cl_stderr, "Number of digits: ");
	fprint(cl_stderr, digits);
	fprint(cl_stderr, "\n");
	fprint(cl_stderr, "Number of repetitions: ");
	fprint(cl_stderr, repetitions);
	fprint(cl_stderr, "\n");

	cl_float_format_t prec = cl_float_format(digits);
	cl_float_format_t prec2 = cl_float_format(digits*2);
	cl_I pow = expt_pos(10,digits);
	cl_I x1 = floor1((sqrt(cl_float(5,prec2))+1)/2 * expt_pos(pow,2));
	cl_I x2 = floor1(sqrt(cl_float(3,prec)) * pow);
	cl_I x3 = pow+1;

	fprint(cl_stderr, "multiplication\n");
	{ cl_I r = x1*x2;
	  { CL_TIMING;
	    for (int rep = repetitions; rep > 0; rep--)
	      { r = x1*x2; }
	  }
	  cout << r << endl << endl;
	}

	fprint(cl_stderr, "division\n");
	{ cl_I_div_t qr = floor2(x1,x2);
	  { CL_TIMING;
	    for (int rep = repetitions; rep > 0; rep--)
	      { qr = floor2(x1,x2); }
	  }
	  cout << qr.quotient << endl << qr.remainder << endl << endl;
	}

	fprint(cl_stderr, "isqrt\n");
	{ cl_I r = isqrt(x3);
	  { CL_TIMING;
	    for (int rep = repetitions; rep > 0; rep--)
	      { r = isqrt(x3); }
	  }
	  cout << r << endl << endl;
	}

	fprint(cl_stderr, "gcd\n");
	{ cl_I r = gcd(x1,x2);
	  { CL_TIMING;
	    for (int rep = repetitions; rep > 0; rep--)
	      { r = gcd(x1,x2); }
	  }
	  cout << r << endl << endl;
	}

}