formatting clock_t variables to show as real time

127 views Asked by At

I am currently looking for a solution with this project I am working on right now where I need to display the clock time of my sorting algorithms in clock ticks and real time. It seems I've got things setup ok, but when I am displaying the clock ticks and actual time I can't get the actual time to display 3 places after the decimal. Here is the code I have setup for the clock stuff (with the necessary header files)

// get beginning time
    beginning = clock();
// --- Function to be clocked ---
// get ending time
    ending = clock();

// set clock variables
    elapsed = ending - beginning;
    totalTime = (elapsed / CLK_TCK);

Some of my data is coming out looking like this when I go to display with cout,

Number of items - Elapsed Clock - Elapsed Time

100000 - 11400 - 11

Where I want it to look like this,

Number of items - Elapsed Clock - Elapsed Time

100000 - 11401 - 11.401

Sorry I know my formatting for this question is awful. Anyone have any advice?

1

There are 1 answers

0
Johan Engblom On
#define __CLOCK_T_TYPE      __SYSCALL_SLONG_TYPE

so clock() gives a long and you want a double... maybe som type cast would help here.