#include <iostream> #include <cstdint> #include <vector> #include <cmath> #include <fstream> #include <ctime> template <typename T> void testValue(T val); template <typename T1, typename T2> void testAssignment(T1 container, T2 val); template <typename T1, typename T2> void testAssignmentCArr(T1 container, T2 val); template <typename T1, typename T2> void testSubtraction(T1 container, T2 val); template <typename T1, typename T2> void testSubtractionCArr(T1 container, T2 val); template <typename T1, typename T2> void testDivision(T1 container, T2 val); template <typename T1, typename T2> void testDivisionCArr(T1 container, T2 val); template <typename T1, typename T2> void testPush(T1 container, T2 val); template <typename T1, typename T2> void testPushCArr(T1 *container, T2 val); using namespace std; const uint16_t ARR_SIZE = 512; ofstream outFile; double cl; vector<unsigned char> vec1(ARR_SIZE); vector<unsigned short> vec2(ARR_SIZE); vector<unsigned int> vec3(ARR_SIZE); vector<unsigned long> vec4(ARR_SIZE); vector<unsigned long long> vec5(ARR_SIZE); vector<uint8_t> vec6(ARR_SIZE); vector<uint16_t> vec7(ARR_SIZE); vector<uint32_t> vec8(ARR_SIZE); vector<uint64_t> vec9(ARR_SIZE); vector<float> vec10(ARR_SIZE); vector<double> vec11(ARR_SIZE); vector<long double> vec12(ARR_SIZE); unsigned char *cArr1 = new unsigned char [ARR_SIZE]; unsigned short *cArr2 = new unsigned short [ARR_SIZE]; unsigned int *cArr3 = new unsigned int [ARR_SIZE]; unsigned long *cArr4 = new unsigned long [ARR_SIZE]; unsigned long long *cArr5 = new unsigned long long [ARR_SIZE]; uint8_t *cArr6 = new uint8_t [ARR_SIZE]; uint16_t *cArr7 = new uint16_t [ARR_SIZE]; uint32_t *cArr8 = new uint32_t [ARR_SIZE]; uint64_t *cArr9 = new uint64_t [ARR_SIZE]; float *cArr10 = new float [ARR_SIZE]; double *cArr11 = new double [ARR_SIZE]; long double *cArr12 = new long double [ARR_SIZE]; int main(int argc, char *argv[]) { outFile.open("result"); testValue((uint8_t) 0xff); testValue((uint16_t) 0xffff); testValue((uint32_t) 0xffffffff); testValue((uint64_t) 0xffffffffffffffff); outFile.close(); } template <typename T> void testValue(T val) { outFile << hex; outFile << endl << " VALUE: 0x" << uint64_t(val) << endl; outFile << dec; outFile << endl << " ."; outFile << endl << " VEC: "; testAssignment(vec1, val); testAssignment(vec2, val); testAssignment(vec3, val); testAssignment(vec4, val); testAssignment(vec5, val); testAssignment(vec6, val); testAssignment(vec7, val); testAssignment(vec8, val); testAssignment(vec9, val); testAssignment(vec10, val); testAssignment(vec11, val); testAssignment(vec12, val); outFile << endl << " CARR: "; testAssignmentCArr(cArr1, val); testAssignmentCArr(cArr2, val); testAssignmentCArr(cArr3, val); testAssignmentCArr(cArr4, val); testAssignmentCArr(cArr5, val); testAssignmentCArr(cArr6, val); testAssignmentCArr(cArr7, val); testAssignmentCArr(cArr8, val); testAssignmentCArr(cArr9, val); testAssignmentCArr(cArr10, val); testAssignmentCArr(cArr11, val); testAssignmentCArr(cArr12, val); outFile << endl << " ."; outFile << endl << " VEC: "; testSubtraction(vec1, 8); testSubtraction(vec2, 8); testSubtraction(vec3, 8); testSubtraction(vec4, 8); testSubtraction(vec5, 8); testSubtraction(vec6, 8); testSubtraction(vec7, 8); testSubtraction(vec8, 8); testSubtraction(vec9, 8); testSubtraction(vec10, 8); testSubtraction(vec11, 8); testSubtraction(vec12, 8); outFile << endl << " CARR: "; testSubtractionCArr(cArr1, 8); testSubtractionCArr(cArr2, 8); testSubtractionCArr(cArr3, 8); testSubtractionCArr(cArr4, 8); testSubtractionCArr(cArr5, 8); testSubtractionCArr(cArr6, 8); testSubtractionCArr(cArr7, 8); testSubtractionCArr(cArr8, 8); testSubtractionCArr(cArr9, 8); testSubtractionCArr(cArr10, 8); testSubtractionCArr(cArr11, 8); testSubtractionCArr(cArr12, 8); outFile << endl << " ."; outFile << endl << " VEC: "; testDivision(vec1, 2); testDivision(vec2, 2); testDivision(vec3, 2); testDivision(vec4, 2); testDivision(vec5, 2); testDivision(vec6, 2); testDivision(vec7, 2); testDivision(vec8, 2); testDivision(vec9, 2); testDivision(vec10, 2); testDivision(vec11, 2); testDivision(vec12, 2); outFile << endl << " CARR: "; testDivisionCArr(cArr1, 2); testDivisionCArr(cArr2, 2); testDivisionCArr(cArr3, 2); testDivisionCArr(cArr4, 2); testDivisionCArr(cArr5, 2); testDivisionCArr(cArr6, 2); testDivisionCArr(cArr7, 2); testDivisionCArr(cArr8, 2); testDivisionCArr(cArr9, 2); testDivisionCArr(cArr10, 2); testDivisionCArr(cArr11, 2); testDivisionCArr(cArr12, 2); outFile << endl << " ."; outFile << endl << " VEC: "; testPush(vec1, 4); testPush(vec2, 4); testPush(vec3, 4); testPush(vec4, 4); testPush(vec5, 4); testPush(vec6, 4); testPush(vec7, 4); testPush(vec8, 4); testPush(vec9, 4); testPush(vec10, 4); testPush(vec11, 4); testPush(vec12, 4); outFile << endl << " CARR: "; testPushCArr(cArr1, 4); testPushCArr(cArr2, 4); testPushCArr(cArr3, 4); testPushCArr(cArr4, 4); testPushCArr(cArr5, 4); testPushCArr(cArr6, 4); testPushCArr(cArr7, 4); testPushCArr(cArr8, 4); testPushCArr(cArr9, 4); testPushCArr(cArr10, 4); testPushCArr(cArr11, 4); testPushCArr(cArr12, 4); outFile << endl; } template <typename T1, typename T2> void testAssignment(T1 container, T2 val) { cl = clock(); for (auto &k : container) for (auto &j : container) for (auto &i : container) { i = val; j = val; k = val; } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; } template <typename T1, typename T2> void testAssignmentCArr(T1 container, T2 val) { cl = clock(); for (uint16_t k = 0; k < ARR_SIZE; k++) for (uint16_t j = 0; j < ARR_SIZE; j++) for (uint16_t i = 0; i < ARR_SIZE; i++) { container[i] = val; container[j] = val; container[k] = val; } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; } template <typename T1, typename T2> void testSubtraction(T1 container, T2 val) { cl = clock(); for (auto &k : container) for (auto &j : container) for (auto &i : container) { i -= val; j -= val; k -= val; } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; } template <typename T1, typename T2> void testSubtractionCArr(T1 container, T2 val) { cl = clock(); for (uint16_t k = 0; k < ARR_SIZE; k++) for (uint16_t j = 0; j < ARR_SIZE; j++) for (uint16_t i = 0; i < ARR_SIZE; i++) { container[i] -= val; container[j] -= val; container[k] -= val; } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; } template <typename T1, typename T2> void testDivision(T1 container, T2 val) { cl = clock(); for (auto &k : container) for (auto &j : container) for (auto &i : container) { i /= val; j /= val; k /= val; } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; } template <typename T1, typename T2> void testDivisionCArr(T1 container, T2 val) { cl = clock(); for (uint16_t k = 0; k < ARR_SIZE; k++) for (uint16_t j = 0; j < ARR_SIZE; j++) for (uint16_t i = 0; i < ARR_SIZE; i++) { container[i] /= val; container[j] /= val; container[k] /= val; } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; } template <typename T1, typename T2> void testPush(T1 container, T2 val) { cl = clock(); for (uint16_t j = 0; j < ARR_SIZE; j++) for (uint16_t i = 0; i < ARR_SIZE; i++) { for (int l = 0; l < val; l++) container.push_back(0); } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; } template <typename T1, typename T2> void testPushCArr(T1 *container, T2 val) { cl = clock(); for (uint16_t j = 0; j < ARR_SIZE; j++) for (uint16_t i = 0; i < ARR_SIZE; i++) { T1 *tmp = new T1 [ARR_SIZE + val]; for (uint16_t l = 0; l < ARR_SIZE + val; l++) { if (l < ARR_SIZE) tmp[l] = container[l]; else tmp[l] = 0; } container = tmp; delete [] tmp; } outFile << (clock() - cl) / CLOCKS_PER_SEC << " "; }