-
Notifications
You must be signed in to change notification settings - Fork 0
/
LLdriver.cpp
105 lines (92 loc) · 3.27 KB
/
LLdriver.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
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <chrono>
#include <iomanip>
#include "LL.hpp"
using namespace std;
int main(int argc, char* argv[])
{
LL linkedList;
int testData[40000]; // all data will be stored in this array
float insert[400];
float search[400];
//search ... filling up arrays
srand(time(nullptr));
int values[100];
int searched[100];
int total = 100;
int trials = 0;
int count = 0;
if(argc < 2) // if there are less than 2 arguments (if no file name is specified)
{
cout << "Failed to open the file.";
return 0;
}
string filename = argv[1]; // the user will enter the file name after writing the ./a.out command on the terminal
ifstream myfile(filename); // creates an input file stream and opens the file
if(!myfile.is_open()) // if the file won't open
{
cout << "Failed to open the file.";
return 0;
}
else
{
string line = "";
auto startTimeInsert = chrono::high_resolution_clock::now();
for(int i = 0; i < 40000; i++) // loops through the array
{
getline(myfile,line,',');
testData[i] = stoi(line);
// if(linkedList.searchLL(values[i]) == NULL) // this was for checking for duplicates but we're allowing duplicates now
// {
linkedList.insert(NULL, testData[i]); // inserts everything at the head
// }
if(i % 100 == 99) // every 100
{
auto endTimeInsert = chrono::high_resolution_clock::now();
double insertTime = (chrono::duration_cast<chrono::nanoseconds>(endTimeInsert-startTimeInsert).count()) * 1e-2;
// float insertTime = (float)((endTimeInsert - startTimeInsert) / 100);
insert[count] = insertTime;
for(int j = 0; j < 100; j++)
{
values[j] = rand() % total; // values 0 to total-1
}
total += 100;
auto startTimeSearch = chrono::high_resolution_clock::now();
for(int j = 0; j < 100; j++)
{
linkedList.searchLL(values[j]);
}
auto endTimeSearch = chrono::high_resolution_clock::now();
double searchTime = (chrono::duration_cast<chrono::nanoseconds>(endTimeSearch-startTimeSearch).count()) * 1e-2;
// float searchTime = (float)((endTimeSearch - startTimeSearch) / 100);
// if(count < 40000)
// {
// cout << insertTime << endl;
// }
search[count] = searchTime;
count++;
startTimeInsert = chrono::high_resolution_clock::now(); // resets clock
}
}
}
ofstream outFile;
string outPut = argv[2];
outFile.open(outPut, ios::out | ios::app);
for(int i = 0; i < 400; i++)
{
outFile << endl << insert[i] << endl;
}
outFile.close();
ofstream outFile2;
string outPut2 = argv[3];
outFile2.open(outPut2, ios::out | ios::app);
for(int i = 0; i < 400; i++)
{
outFile2 << endl << search[i] << endl;
}
outFile2.close();
return 0;
}