c++ - Discrepancies between g++ output and Visual Studio Output. Float Variables -
i testing out using clock_t function's in c++ , ran across problem. when compile on 2 different compilers. visual studio on windows 7 computer (2012), , g++ on unix scheme called "ranger". when compiled code in effort output time in seconds (up thousandth of second) takes run different sort functions, seems g++ compiler ignores effort split time stamp 1000 in order convert milliseconds sec format. advice? there difference between g++ , visual studio's compiler in regard's this?
a short code snippet(output , division):
//select sort begin = clock(); //begin time selectionsort(array, n); end = clock(); //end time d_select = ((float)(end/1000.0) - (float)(begin/1000.0)); //calculates time in ms, , converts ms, float second. //output info cout << setprecision(3) << fixed; //set precision 3 decimal places, fixed output (0's displayed regardless of rounding) cout << n << "\t" << d_bubble << "\t" << d_insert << "\t" << d_merge << "\t" << d_quick << "\t" << d_select << endl; visual studio output (correct):
n bubble insert merge quick select 100000 12.530 1.320 0.000 0.030 2.900 unix output(incorrect) :
n bubble insert merge quick select 100000 51600.000 11700.000 30.000 150.000 18170.000 any suggestions? thanks!
divide clocks_per_sec, not 1000. on unix, , posix in general, clock() gives value in microseconds, not milliseconds.
note that, , clock_t, integers; if want fractional seconds, convert floating-point format before dividing:
d_select = float(end - begin) / clocks_per_sec; c++ visual-studio-2012 io g++ iomanip
No comments:
Post a Comment