-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
90 lines (62 loc) · 2.17 KB
/
main.cpp
File metadata and controls
90 lines (62 loc) · 2.17 KB
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
//
// main.cpp
// search
//
// Created by Ayne Delgado on 2/8/15.
// Last edited on
//
//I Ayne Delgado have not used any code other than my own (or that in the textbook) for this project.
//I also have not used any function or data-structure from the Standard-Template Library.
//I understand that any violation of this disclaimer will result in a 0 for the project.
#include <iostream>
#include <ctime>
#include "Search.h"
using namespace std;
//----------------------CONSTANTS----------------------
int const BIG = 10000;
int const GIANT = 1000000;
int const MY_SEED = 5;
int const FIND_ME = 100;
double const SEC_TO_MICRO=1000000;
int main()
{
//Two searches declared, same size and seed
Search binary(BIG,MY_SEED);
Search sequential(BIG, MY_SEED);
//One sorted random array for binary search and one random array for sequential search
binary.init_sorted_array();
sequential.init_array();
//Testing iterative binary search. Should be the fastest
clock_t start1 = clock();
for(int i = 0; i<GIANT; i++)
{
binary.iterative_binary_find(FIND_ME);
}
clock_t end1 = clock();
clock_t diff1 = end1-start1;
//Testing recursive binary search. Should be second fastest
clock_t start2 = clock();
for(int i = 0; i<GIANT; i++)
{
binary.recursive_binary_find(FIND_ME);
}
clock_t end2 = clock();
clock_t diff2 = end2-start2;
//Testing sequential search. Should take longest
clock_t start3 = clock();
for(int i = 0; i<GIANT; i++)
{
sequential.sequential_find(FIND_ME);
}
clock_t end3 = clock();
clock_t diff3 = end3-start3;
//Calculate clocks to microseconds and output
cout<<"The iterative binary search took "<<(((double)diff1)/CLOCKS_PER_SEC)*SEC_TO_MICRO<<" microseconds";
cout<<endl;
cout<<"The recursive binary search took "<<(((double)diff2)/CLOCKS_PER_SEC)*SEC_TO_MICRO<<" microseconds";
cout<<endl;
cout<<"The sequential search took "<<(((double)diff3)/CLOCKS_PER_SEC)*SEC_TO_MICRO<<" microseconds";
cout<<endl;
//system("PAUSE");
return 0;
}