File: timebench2a.cc

package info (click to toggle)
cln 1.3.4-4
  • links: PTS
  • area: main
  • in suites: buster
  • size: 10,724 kB
  • sloc: cpp: 80,930; sh: 11,982; ansic: 3,278; makefile: 1,313
file content (80 lines) | stat: -rw-r--r-- 1,735 bytes parent folder | download | duplicates (10)
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 <cln/number.h>
#include <cln/io.h>
#include <cln/integer.h>
#include <cln/integer_io.h>
#include <cln/float.h>
#include <cln/real.h>
#include <cstdlib>
#include <cstring>
#include <cln/timing.h>

using namespace std;
using namespace cln;

int 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);
	
	cerr << "Number of digits: " << digits << endl;
	cerr << "Number of repetitions: " << repetitions << endl;

	float_format_t prec = float_format(digits);
	float_format_t prec2 = 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;

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

	cerr << "division" << endl;
	{ 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;
	}

	cerr << "isqrt" << endl;
	{ cl_I r = isqrt(x3);
	  { CL_TIMING;
	    for (int rep = repetitions; rep > 0; rep--)
	      { r = isqrt(x3); }
	  }
	  cout << r << endl << endl;
	}

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

}