-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.cpp
128 lines (119 loc) · 2.52 KB
/
test.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
//#include "boundary.h"
//#include <random>
#include "random_mars.h"
#include <ctime>
using namespace std;
/*
struct A{
int *f;
public:
A(){
f = new int;
}
void init(int sz)
{
//int sz=5;
*f = sz;
}
void output(){cout<<"f= "<<*f<<endl;}
~ A(){delete f;}
};*/
class Base{
public:
int a;
int *x;
public:
Base(int a_){a=a_;x=NULL;}
virtual ~Base(){//delete x;
cout<<"base destructor"<<endl;
}
virtual void out(){cout<<a*a<<endl;}
};
class Child: public Base{
public:
int b;
public:
Child(int a_, int b_):Base(a_){
b=b_;
x=new int[5];
for (int i=0;i<5;i++)
x[i]=i;
}
~Child(){delete x;
cout<<"child destructor"<<endl;
}
void out(){cout<<b*b<<endl;}
};
int main()
{
/*Base *pb;
Child child(1,2);
pb = &child;
pb->out();
for (int i=0;i<5;i++)
cout<<"x "<<pb->x[i]<<endl;
*/
/*
const int nrolls=10000;
const int nstars=100;
std::default_random_engine generator;
std::normal_distribution<double> distribution(5.0,2.0);
RanMars *random;
random = new RanMars(5);
int p[10]={};
double min, max;
min=0;
max=0;
for (int i=0; i<nrolls;++i){
//double number = distribution(generator);
double number = random->gaussian();//distribution(generator);
if (number > max) max=number;
if (number < min) min=number;
if ((number >=0.0) &&(number<10.0)) ++p[int(number)];
}
std::cout<<"normal distribution (5.0,2.0):"<<std::endl;
std::cout<<"max, min"<<max<<" "<<min<<std::endl;
for (int i=0;i<10;++i){
std::cout<<i<<"-"<<(i+1)<<":";
std::cout<<std::string(p[i]*nstars/nrolls,'*')<<std::endl;
}
*/
/*for (int i=0;i<5;i++)
for (int j=0;j<5;j++){
if (i==0 || i==4) {
if (j==1 || j==2) continue;
}
std::cout<<"i,j="<<i<<" "<<j<<std::endl;
}*/
clock_t begin=clock();
for (int k=0;k<1000000;k++){
for (int i=-1;i<100;i++){
int j=(i+100)%100;
}
}
clock_t end=clock();
double elapsedSecs = double(end-begin)/CLOCKS_PER_SEC;
cout<<"mod time elapsed "<<elapsedSecs<<endl;
begin=clock();
for (int k=0;k<1000000;k++){
for (int i=-1;i<100;i++){
int j=i;
if (j==-1) j += 100;
//if (j==101) j -= 100;
}
}
end=clock();
elapsedSecs = double(end-begin)/CLOCKS_PER_SEC;
cout<<"if time elapsed "<<elapsedSecs<<endl;
/*
int a=3;
double c=3.0;
int b=2;
int d;
std::cout<<"a/b "<<a/b<<std::endl;
std::cout<<"c/b "<<c/b<<std::endl;
d = c/b*b;
cout<<"d "<<d<<endl;*/
return 0;
}