![]() |
|
#1
|
|||
|
|||
Sorting Algorithms by TimeHello again everyone. We have completed a project after a few months and a lot of help but for some reason we are still having problems. The project compiles properly without errors but the results are incorrect. Basically we are using 4 sorting algorithms in order to calculate how much time it takes to generate random numbers and the time that is taken. We have no problems generating the integers but the times seem to be way off (Time seems to always be 0) . My brain is fried and so are my teammates'. I was hoping that someone could point us in the right direction as to why the times are off. We are very new to the time function and had to read a few books and templates to complete this much
I've included our output at the end of the code. Please let us know if we are overlooking something simple Thanks in advance CPP / C++ / C Code:
//output: Code:
Last edited by LuciWiz : 03-May-2005 at 00:49.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|||
|
#2
|
||||
|
||||
|
Hello,
I've ran into this problem before. I know of a way to fix this. There are two steps. Step #1 Change all the occurrences of: CPP / C++ / C Code:
To: CPP / C++ / C Code:
Since you want to see more than just the seconds that pass. This will allow you to see any milliseconds that pass. Step 2 Change all of the occurrences of: CPP / C++ / C Code:
To: CPP / C++ / C Code:
Where * denotes start and end. So both of the variables will equal clock() rather than time( NULL ) - Stack Overflow __________________
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [C] / [C++] tags. Your question may have been asked before, try the search facility. |
|
#3
|
||||
|
||||
|
Here's what I see in your code:
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Also, the time() function only has a resolution of 1 second. Many, if not most, of your sorts will probably run in under a second. For this type of project you'll want a millisecond resolution, which means looking into other time functions. Look thru your book or google for other options you can use. __________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes Last edited by LuciWiz : 03-May-2005 at 04:31.
Reason: Broken BB codes...
|
|
#4
|
|||
|
|||
|
[Also, cross-posted.]
|
|
#5
|
|||
|
|||
Adjustments Made to Sorting Algorithms-TimeHello, I've rewritten the code and now see times that look correct. I know understand that the 0's were because the sorting happened under 1 second.
It still doesn't give me the times for everything but it seems that I am now on the right track Thanks for your help Is there a way that I can a more precise time so that I can get a time for every method I will now work on what you suggested WaltP Thanks for all of you help I really appreaciate it CPP / C++ / C Code:
Last edited by LuciWiz : 03-May-2005 at 00:50.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simulation Problem | wu_weidong | C++ Forum | 7 | 12-Mar-2005 22:56 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 15:13 |
| Re: Programming Techniques | WaltP | C Programming Language | 0 | 09-Mar-2004 23:56 |
| time Problem | zuzupus | MySQL / PHP Forum | 9 | 24-Jul-2003 07:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The