#include #include #include // Function declarations void byteArrayToHexString_point(const unsigned char* byteArray, size_t length, char* hexString); void byteArrayToHexString_snprintf(const unsigned char* byteArray, size_t length, char* hexString); void byteArrayToHexString_idx(const unsigned char* byteArray, size_t length, char* hexString); int main() { // Example large byte array size_t length = 256; // 1 million bytes unsigned char *byteArray = (unsigned char*)malloc(length * sizeof(unsigned char)); for (size_t i = 0; i < length; i++) { byteArray[i] = i % 256; // Filling with example data } // Allocate memory for the hex string (2 characters per byte + 1 for the null terminator) char* hexString = (char*)malloc((length * 2 + 1) * sizeof(char)); if (hexString == NULL || byteArray == NULL) { fprintf(stderr, "Memory allocation failed\n"); return EXIT_FAILURE; } int loop_times=1000; // Measure the time taken for the conversion clock_t start = clock(); for(int i=0; i> 4) & 0x0F]; *ptr++ = hexChars[byteArray[i] & 0x0F]; } *ptr = '\0'; // Null-terminate the string } // Function to convert byte array to hex string void byteArrayToHexString_snprintf(const unsigned char* byteArray, size_t length, char* hexString) { for (size_t i = 0; i < length; i++) { sprintf(hexString + (i * 2), "%02x", byteArray[i]); } hexString[length * 2] = '\0'; // Null-terminate the string } void byteArrayToHexString_idx(const unsigned char* byteArray, size_t length, char* hexString) { const char hexChars[] = "0123456789abcdef"; for (size_t i = 0; i < length; i++) { hexString[i * 2] = hexChars[(byteArray[i] >> 4) & 0x0F]; hexString[i * 2 + 1] = hexChars[byteArray[i] & 0x0F]; } hexString[length * 2] = '\0'; // Null-terminate the string }