Test Results:
Test Std :: Vector
Test Std :: Vector
Test Std :: Vector
Test Std :: Vector
in conclusion:
INT, long, float, double, -, * calculation performance is the same, the division is slow, more occupied, to avoid division.
That is: the calculation time of adding, minus, and multiplication is independent of the data type, so it is possible to use a more accurate FLOAT, DOUBLE type, which does not affect the program speed.
The following is a test code (please generate a console type with VC7, save the following code as a file join item, Release mode compilation):
#include
Template DWStartTime = clock (); for (int NTIMES = 0; NTIMES <100000; NTIMES) // calculated for the number of times for calculation for (INT i = 0, nsize = vec.size (); i // Generate test data std :: generate (myvecint.begin (), myvecint.ere (); std :: generate (myveclong.begin (), myveclong.erate (); std :: generate MYVECFLOAT.EGIN (), MyVecfloat.end (), Boost :: Bind (std :: divide :: bind)); std :: transform (MyVecfloat.begin (), MyVecfloat.end (), MyVecdouble.begin (), Boost :: Bind (std :: multiplies // Show before n = 6; std :: for_each (myvecint.begin (), myvecint.begin () n, std :: cout << boost :: lambda :: _ 1 << '/ t' ); std :: cout << "/ n / n"; std :: for_each (MyVeclong.begin (), myveclong.begin () n, std :: cout << boost :: lambda :: _ 1 << ' / t '); std :: cout << "/ n / n"; std :: for_each (MyVecfloat.begin (), myVecfloat.begin () n, std :: cout << boost :: lambda :: _ 1 << '/ t'); std :: cout << "/ n / n"; std :: for_each (myVecdouble.begin (), myVecdouble.begin () n, std :: cout << boost :: lambda :: _ 1 << '/ t'); std :: cout << "/ n / n"; std :: ostream & of = std :: cout; // Out to screen // std :: OFSTREAM OF ("c : //testtime.txt ", std :: os_base :: out); // Output to File Test (MyVeclong, Of); Test (MyVecfloat, of); Test (MyVecdouble, of); //of.close (); // Close file // Show before n data std :: for_each (myvecint.begin (), myvecint.begin () n, std :: cout << boost :: lambda :: _ 1 << '/ t'); std :: Cout << "/ n / n"; std :: for_each (MyVeclong.begin (), myveclong.begin () n, std :: cout << boost :: lambda :: _ 1 << '/ t'); Std :: cout << "/ n"; std :: for_each (myVecfloat.begin (), myVecfloat.begin () n, std :: cout << boost :: lambda :: _ 1 << '/ t '); std :: cout << "/ n / n"; std :: for_each (myVecdouble.begin (), myvecdouble.begin () n, std :: cout << boost :: lambda :: _ 1 << '/ t'); std :: cout << "/ n / n";