Taking too long to print the execution time

  • Thread starter Thread starter Shamprikta Mehreen
  • Start date Start date
S

Shamprikta Mehreen

Guest
My assignment is to perform 1) Millions of operations with millions of values, 2) millions of operations with thousands of fixed values repeatedly. But it is taking too long time to show me the execution time. Can someone help me how can I get it faster? Here is my code:


#include<iostream>
#include <ctime>


#define MIL 1000000
#define BIL 1000
using namespace std;


long stack[1000000], top;

//stack initialization
void initStack() {
top = -1;
}

//push operation
void push() {
for( int i=top; i<=MIL; i++){
top++;
}

}

//pop operation
void pop() {
for (int i = MIL; i <= top; i--) {
top--;
}
}


int main() {
int start_s = clock();
initStack();
for (int i = 0; i < MIL; i++)
{
push();
pop();
}

for (int j = 0; j <= BIL; j++)
{
for (int i = 0; i < MIL; i++)
{
push();
pop();
}

}

// calculate execution time
int stop_s = clock();
cout << "time: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << endl;

system("PAUSE");
}

Continue reading...
 
Back
Top