Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

Calculating Search Times

Ok, I'm going crazy!

   I have a basic program to make.  It is suppose to calculate the average time it takes to do a search.  
My code looks like this:

//sequential search function
        //x = search value
     clock_t start, end;
     start = clock();
     for (i =0; i<n && CurrentArray[i] !=x; i++)
     {
          if (i==n)
               exit (.1);     //ERROR! x not found!
     }    
     end = clock();
     return end-start;

I preform this search about numerous times, with randomly chosen x values .
ok so the problem I have is that no matter how large my array is, the return time is ALWAYS zero, IF I allow the function to run on it's on.  However if I debug it, executing the code line by line I am able to get none zero times.  
PLEASE HELP!!!!
I have already recieved a 60 for this project, but have midterms soon!
0
wdrake_98
Asked:
wdrake_98
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:
The problem is: Your search is too fast.


It's completing before the system clock timer ticks to the next interval.

Try doing 1000 or 100,000 searches for the same item between checks of the clock and compute the search time from that.


kdo
0
 
wdrake_98Author Commented:
Very FAST response!!!!
I just may have to sign up for the premium service!
It worked... had to increase it to like 1000, searches between the clocks but it worked...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now