What I'm actually trying to do is figure out how "clock()" can accurately time the amount of time it takes to "push" in the amount of elements during each loop from "minsize" to "maxsize"
Once I know how to properly use the "clock()" function, I will then compare the "push" times of the STL stack with my own version of the stack class....
Where I am running into issues is I am not able to properly determine the amount of time it is taking for STL stack to "push" in the amount of elements.
Simply put...I know that I can put clock() start before I begin the "push" for loop, and I know I can put clock() end after the for loop.
But I need help with figuring out how to find how much time it takes for each loop of "push" from minsize to maxsize...
for example: I need to know how long it takes to push 100 elements first...then 101 elements...and then 102 elements...and then 103 elements...and then 104 elements...etc...all the way to maxsize.
Your first solution seems like it will work, but it will take some tweaking for my specific example..so I will try and see what I can come up with.
I really appreciate your help btw!
Do you think this is an accurate measurement over the for loop?
My code now:
----------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int j = minsize;
int count = 0;
for(int i = minsize; i < maxsize; i = i + stepsize){
stack<int> s;
clock_t start1 = clock();
for(int x = 0; x < j; x++){
s.push(x);
//cout<<"s size: " << mys.size() << endl;
}
clock_t stacktdif = clock();
stackt = (float)(stacktdif - start1) * 1000.0 / (float) CLOCKS_PER_SEC;
stacktsum+= stackt;
cout << fixed << i << ":\t" << setprecision(3) << stacktsum;
}
|