diff --git a/.gitignore b/.gitignore index aef4ce1..dbfdab2 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ src/tests/test_normalize_path src/tests/test_sorted_array src/tests/test_sorted_queue src/tests/test_thread_local +src/tests/test_memcpy # other *.swp diff --git a/src/connection_pool.c b/src/connection_pool.c index b82223c..5471572 100644 --- a/src/connection_pool.c +++ b/src/connection_pool.c @@ -266,7 +266,7 @@ int conn_pool_async_connect_server_ex(ConnectionInfo *conn, return result; } -static inline void conn_pool_get_key(const ConnectionInfo *conn, +static inline void conn_pool_get_key(const ConnectionInfo *conn, char *key, int *key_len) { *key_len = sprintf(key, "%s-%u", conn->ip_addr, conn->port); @@ -710,7 +710,7 @@ int conn_pool_parse_server_info(const char *pServerStr, if (getIpaddrByNameEx(parts[0], pServerInfo->ip_addr, sizeof(pServerInfo->ip_addr), &pServerInfo->af) == INADDR_NONE) - { + { logError("file: "__FILE__", line: %d, " "host: %s, invalid hostname: %s!", __LINE__, pServerStr, parts[0]); diff --git a/src/tests/Makefile b/src/tests/Makefile index a3c7040..570084c 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -11,9 +11,13 @@ ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blo test_server_id_func test_pipe test_atomic test_file_write_hole test_file_lock \ test_pthread_wait test_thread_pool test_data_visible test_mutex_lock_perf \ test_queue_perf test_normalize_path test_sorted_array test_sorted_queue \ - test_thread_local + test_thread_local test_memcpy all: $(ALL_PRGS) + +test_memcpy: test_memcpy.c + $(CC) -g -Wall -o $@ $< $(LIB_PATH) $(INC_PATH) + .c: $(COMPILE) -o $@ $< $(LIB_PATH) $(INC_PATH) .c.o: diff --git a/src/tests/test_memcpy.c b/src/tests/test_memcpy.c new file mode 100644 index 0000000..fb053f7 --- /dev/null +++ b/src/tests/test_memcpy.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 YuQing <384681@qq.com> + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the Lesser GNU General Public License, version 3 + * or later ("LGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the Lesser GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include "fastcommon/shared_func.h" + +#define BUFF_SIZE (4 * 1024 * 1024) + +int main(int argc, char *argv[]) +{ + char *buff1; + char *buff2; + char *dest; + int64_t start_time, end_time; + char time_buff[32]; + int i; + + buff1 = malloc(BUFF_SIZE); + buff2 = malloc(BUFF_SIZE); + dest = malloc(BUFF_SIZE); + + memset(buff1, 'a', BUFF_SIZE); + memset(buff2, 'b', BUFF_SIZE); + memset(dest, 0, BUFF_SIZE); + + start_time = get_current_time_us(); + for (i=0; i<16 * 1024; i++) { + if (i % 2 == 0) { + memcpy(buff2, buff1, BUFF_SIZE); + } else { + memcpy(dest, buff2, BUFF_SIZE); + } + } + + end_time = get_current_time_us(); + printf("time used: %s us\n", long_to_comma_str( + end_time - start_time, time_buff)); + return 0; +} +