Skip to content
Snippets Groups Projects
Commit 05f14c45 authored by HAQUIN ELOUAN's avatar HAQUIN ELOUAN :surfer:
Browse files

Trying to parse c++ values into a csv which can be read in R

parent a66b74a5
Branches
No related merge requests found
#include "Vector3D.h"
......@@ -38,9 +38,9 @@ public:
Vector3D& operator=(const Vector3D& other) { this->set_X(other.get_X()); this->set_Y(other.get_Y()); this->set_Z(other.get_Z()); return *this; }
Vector3D& operator=(Vector3D& other) { this->set_X(other.get_X()); this->set_Y(other.get_Y()); this->set_Z(other.get_Z()); return *this; }
Vector3D operator*(const Vector3D& other) { Vector3D<float> vec1(false, 0, 0, 0); vec1.set_X(other.get_X() * this->get_X()); vec1.set_Y(other.get_Y() * this->get_Y()); vec1.set_Z(other.get_Z() * this->get_Z()); return vec1; }
Vector3D operator+(const Vector3D& other) { Vector3D<float> vec1(false, other.get_X() + this->get_X(), other.get_Y() + this->get_Y(), other.get_Z() + this->get_Z()); return vec1; }
Vector3D operator-(const Vector3D& other) { Vector3D<float> vec1(false, 0, 0, 0); vec1.set_X(this->get_X() - other.get_X()); vec1.set_Y(this->get_Y() - other.get_Y()); vec1.set_Z(other.get_Z() - this->get_Z()); return vec1; }
Vector3D operator*(const Vector3D& other) { Vector3D<float> vec1( 0, 0, 0); vec1.set_X(other.get_X() * this->get_X()); vec1.set_Y(other.get_Y() * this->get_Y()); vec1.set_Z(other.get_Z() * this->get_Z()); return vec1; }
Vector3D operator+(const Vector3D& other) { Vector3D<float> vec1( other.get_X() + this->get_X(), other.get_Y() + this->get_Y(), other.get_Z() + this->get_Z()); return vec1; }
Vector3D operator-(const Vector3D& other) { Vector3D<float> vec1( 0, 0, 0); vec1.set_X(this->get_X() - other.get_X()); vec1.set_Y(this->get_Y() - other.get_Y()); vec1.set_Z(other.get_Z() - this->get_Z()); return vec1; }
Vector3D operator*(float scalaire) { Vector3D<float> vec1(false, 0, 0, 0); vec1.set_X(this->get_X() * scalaire); vec1.set_Y(this->get_Y() * scalaire); vec1.set_Z(this->get_Z() * scalaire); return vec1; }
Vector3D operator+(float scalaire) { Vector3D<float> vec1(false, 0, 0, 0); vec1.set_X(this->get_X() + scalaire); vec1.set_Y(this->get_Y() + scalaire); vec1.set_Z(this->get_Z() + scalaire); return vec1; }
Vector3D operator-(float scalaire) { Vector3D<float> vec1(false, 0, 0, 0); vec1.set_X(this->get_X() - scalaire); vec1.set_Y(this->get_Y() - scalaire); vec1.set_Z(this->get_Z() - scalaire); return vec1; }
......@@ -57,7 +57,7 @@ public:
//TEST FUNCTIONS
bool isPerpendicular(Vector3D& vec2) { return angle_With(this, vec2) == 90; }
bool isNull() { return this.get_X() == 0 && this.get_Y() == 0 && this.get_Z(); }
bool isParallel(Vector3D& vec2) { return this.scalar_Between(v2) / this.getLength() * v2.getLength()) > 1; }
bool isParallel(Vector3D& vec2) { return this.scalar_Between(vec2) / this.getLength() * vec2.getLength() > 1; }
bool isNormalised() { return this->get_Norme() == 1; }
bool isOpposed(Vector3D& vec2) { return this->isParallel(vec2) && this->get_X() + vec2.get_X() < this->get_X() && this->get_Y() + vec2.get_Y() < this->get_Y() && this->get_Z() + vec2.get_Z() < this->get_Z(); }
......
#include <iostream>
#include <chrono>
#include <ctime>
#include <numeric>
#include <fstream>
#include <vector>
#include "Vector3D.h"
#include "Array.h"
#include "LinkedList.h"
#include "windows.h"
#include "psapi.h"
double timeUsedByVectorsAddition(int nbVectorAdditions) {
Vector3D<float> v1(1.0f, -1.0f, 1.0f);
Vector3D<float> v2(1.0f, -1.0f, 1.0f);
auto start = std::chrono::system_clock::now();
for (int i = 0; i < nbVectorAdditions; ++i) {
v1 + v2;
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
return elapsed_seconds.count() ;
}
double timeUsedBySTDVectorsAddition(int nbVectorAdditions) {
auto start = std::chrono::system_clock::now();
std::vector<int> v1 = { 1, -1, 1 };
std::vector<int> v2 = { 1, -1, 1 };
for (int i = 0; i < nbVectorAdditions; ++i) {
accumulate(v1.begin(), v1.end(), 0);
}
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
return elapsed_seconds.count();
}
int main()
{
......@@ -13,6 +67,29 @@ int main()
LinkedList<int> L1(15);
std::ofstream myfile;
myfile.open("example.csv");
myfile << "My_time <-" << "(";
for (int nbTest = 1; nbTest < 100000; nbTest *= 10) {
double test1 = timeUsedByVectorsAddition(nbTest) * 1000;
myfile << test1 << ",";
}
myfile << ")";
myfile << "\n";
myfile << "STD_time <-" << "(";
for (int nbTest = 1; nbTest < 100000; nbTest *= 10) {
double test1 = timeUsedBySTDVectorsAddition(nbTest)*1000;
myfile << test1 << ",";
}
myfile << ")";
myfile.close();
return 0;
system("Pause");
return 0;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment