-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.h
54 lines (47 loc) · 1.17 KB
/
io.h
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
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <chrono>
using namespace std;
void writeVector(string fileName, double* vector, int size) {
ofstream fout(fileName);
//fout.setf(ios_base::fixed,ios_base::floatfield);
fout <<size<< endl;
for (int i = 0; i < size; i++) {
fout << vector[i]<<endl;
}
fout.flush();
fout.close();
}
template <class T>
void writeMatrix(string fileName, T matrix, int size) {
ofstream fout(fileName);
fout <<size<< endl;
fout.setf(ios_base::scientific);
for (int i = 0; i <size; i++) {
for (int j = 0; j < size; j++)
fout << matrix[i][j] << " ";
fout << endl;
}
fout.flush();
fout.close();
}
class Timer{
public:
typedef std::chrono::time_point<std::chrono::system_clock> timePoint;
void start();
void stop();
double interval();
private:
timePoint start_, stop_;
};
void Timer::start(){
start_ = std::chrono::system_clock::now();
}
void Timer::stop(){
stop_ = std::chrono::system_clock::now();
}
double Timer::interval(){
return ((double)std::chrono::duration_cast<std::chrono::milliseconds>(stop_-start_).count()) / 1000;
}