I am having trouble getting my program to find the time it takes a selection sort to sort through 100,000 randomly generated items. What have I done wrong? I keep getting a negative number for the time lapsed.
If I recall correctly, the time() function does not support milliseconds. By multiplying it with 1000 probably already massed around with the value (possibily already negative number now)
@cire My compiler does not give me any warnings. What should I do to fix this though? I am only allowed to use ctime and time(0). Also if I remove the *1000 it returns 0. I still have an issue.
Two reasons not to use std::chrono::high_resolution_clock
a. std::chrono::high_resolution_clock does not measure processor time.
b. std::chrono::high_resolution_clock may not be monotonic: it can go back in time.
For measuring single-threaded in-memory sort performance, all the clocks in std::chrono are the wrong clocks. std::time() too is the wrong clock for the same reasons; in addition it typically has a coarse resolution.
To measure the (approximate) processor time, use std::clock()
The other suggestions are all valid but I want to address why you're seeing a negative number. The problem is because you're overflowing the precision of a time_t when you multiply by 1000. Time_t is typically a 32 bit signed integer and the current value of "now" is around 1.4 billion.