From d9d62556218091332f2a06a7ac6516a50698a44a Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Thu, 11 Sep 2025 12:07:45 +0800 Subject: [PATCH] test_fast_buffer.c support int2hex --- src/tests/test_fast_buffer.c | 41 +++++++++++++++++++++----------- src/tests/test_file_write_hole.c | 3 ++- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/tests/test_fast_buffer.c b/src/tests/test_fast_buffer.c index 38e7731..956fd7c 100644 --- a/src/tests/test_fast_buffer.c +++ b/src/tests/test_fast_buffer.c @@ -29,7 +29,8 @@ typedef enum { TEST_TYPE_ITOA = 1, TEST_TYPE_FTOA, - TEST_TYPE_MIXED + TEST_TYPE_INT2HEX, + TEST_TYPE_APPEND } TestType; typedef enum { @@ -160,7 +161,7 @@ static inline int cache_binlog_filename_by_append( static void usage(const char *program) { - fprintf(stderr, "Usage: %s [-t {itoa | ftoa | mixed}]\n", + fprintf(stderr, "Usage: %s [-t {itoa | ftoa | int2hex | append}]\n", program); } @@ -180,8 +181,9 @@ int main(int argc, char *argv[]) double d = 123.456; int ch; int i; + int len; int64_t start_time_us; - int append_time_us; + int convert_time_us; int sprintf_time_us; double ratio; FastBuffer buffer; @@ -211,8 +213,11 @@ int main(int argc, char *argv[]) } else if (strcasecmp(optarg, "ftoa") == 0) { test_type = TEST_TYPE_FTOA; caption = "ftoa"; - } else if (strcasecmp(optarg, "mixed") == 0) { - test_type = TEST_TYPE_MIXED; + } else if (strcasecmp(optarg, "int2hex") == 0) { + test_type = TEST_TYPE_INT2HEX; + caption = "int2hex"; + } else if (strcasecmp(optarg, "append") == 0) { + test_type = TEST_TYPE_APPEND; caption = "append"; } else { fprintf(stderr, "invalid type: %s\n", optarg); @@ -225,7 +230,7 @@ int main(int argc, char *argv[]) } } - if (test_type == TEST_TYPE_MIXED) { + if (test_type == TEST_TYPE_APPEND) { memset(&record, 0, sizeof(record)); record.op_type = 'C'; record.slice_type = DA_SLICE_TYPE_FILE; @@ -241,7 +246,7 @@ int main(int argc, char *argv[]) start_time_us = get_current_time_us(); for (i=0; i 0) { - ratio = (double)sprintf_time_us / (double)append_time_us; + if (convert_time_us > 0) { + ratio = (double)sprintf_time_us / (double)convert_time_us; } else { ratio = 1.0; } printf("sprintf time: %d ms, %s time: %d ms, " "sprintf time / %s time: %d%%\n", - sprintf_time_us / 1000, caption, append_time_us / 1000, + sprintf_time_us / 1000, caption, convert_time_us / 1000, caption, (int)(ratio * 100.00)); fast_buffer_destroy(&buffer); diff --git a/src/tests/test_file_write_hole.c b/src/tests/test_file_write_hole.c index 202c2ab..2c878bd 100644 --- a/src/tests/test_file_write_hole.c +++ b/src/tests/test_file_write_hole.c @@ -32,6 +32,7 @@ int main(int argc, char *argv[]) int fd; int result; int n; + int i; char buf[1024]; if (argc < 2) { @@ -69,7 +70,7 @@ int main(int argc, char *argv[]) return errno != 0 ? errno : EIO; } - for (int i=0; i<5; i++) { + for (i=0; i<5; i++) { if (lseek(fd, 0, SEEK_SET) < 0) { logError("file: "__FILE__", line: %d, " \ "lseek file %s fail, " \