just for some simple algorithms for multiplying potentially very big numbers i'm trying to get an accurate reading on how long they take, but can't get non-zero readings using clock() for times under 0.01 seconds, even though CLOCKS_PER_SEC is 1000000 on my machine.
Here's the relevant portion of the code:
If the length of num1 and num2 is 128, for example, I always get a run_time of 0, but at length 256, i get a run_time of .010000. i'd like to be able to measure short run times here, too. any ideas?Code:const int BASE = 8; vector<short> num1, num2, result; clock_t start, end; double run_time; /* code to create num1 and num2 randomly of a given length */ ... start = clock(); result = mult_full(num1, num2, BASE); end = clock(); run_time = static_cast<double>(end - start) / CLOCKS_PER_SEC; cout.setf(ios_base::fixed); cout << "Run time using clock() for random integers of length " << len << ": " << setprecision(6) << run_time << endl; cout << "CLOCKS_PER_SEC is " << CLOCKS_PER_SEC << endl;



LinkBack URL
About LinkBacks




