-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.cpp
66 lines (49 loc) · 1.15 KB
/
test2.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
#include <iostream>
#include <cstdlib>
class Vector {
protected:
float a,b,c;
public:
Vector(float a, float b, float c) {
this->a = a;
this->b = b;
this->c = c;
}
float dot(Vector other) {
return this->a * other.a + this->b * other.b + this->c * other.c;
}
Vector cross(Vector other) {
return Vector(
this->b * other.c - this->c * other.b,
this->c * other.a - this->a * other.c,
this->a * other.b - this->b * other.a
);
}
void print() {
std::cout << "[ " << this->a << ", " << this->b << ", " << this->c << " ]" << std::endl;
}
};
int * randomList(unsigned int size) {
int * l = new int[size];
for (unsigned int i=0; i<size; i++)
l[i] = rand();
return l;
}
int main() {
unsigned int loops = 5e7;
unsigned int counter = 0;
std::cout << "looping " << loops << " times" << std::endl;
int * l = randomList(loops);
for(unsigned int i=0; i < loops; i++) {
Vector v1(1*l[i],2*l[i],3*l[i]);
Vector v2(9*l[i],8*l[i],7*l[i]);
v1.dot(v2);
v1.cross(v2);
counter++;
}
std::cout << "counter = " << counter << std::endl;
// v1.print();
// v2.print();
// std::cout << v1.dot(v2) << std::endl;
// v1.cross(v2).print();
}