Compare commits

..

No commits in common. "d9d62556218091332f2a06a7ac6516a50698a44a" and "a4cae13e07bbf40ac3c3729fd9775a752d0e7ff6" have entirely different histories.

2 changed files with 34 additions and 116 deletions

View File

@ -26,13 +26,6 @@
#include "fastcommon/fast_buffer.h" #include "fastcommon/fast_buffer.h"
#include "fastcommon/sched_thread.h" #include "fastcommon/sched_thread.h"
typedef enum {
TEST_TYPE_ITOA = 1,
TEST_TYPE_FTOA,
TEST_TYPE_INT2HEX,
TEST_TYPE_APPEND
} TestType;
typedef enum { typedef enum {
DA_SLICE_TYPE_FILE = 'F', /* in file slice */ DA_SLICE_TYPE_FILE = 'F', /* in file slice */
DA_SLICE_TYPE_CACHE = 'C', /* in memory cache */ DA_SLICE_TYPE_CACHE = 'C', /* in memory cache */
@ -159,39 +152,20 @@ static inline int cache_binlog_filename_by_append(
return p - full_filename; return p - full_filename;
} }
static void usage(const char *program)
{
fprintf(stderr, "Usage: %s [-t {itoa | ftoa | int2hex | append}]\n",
program);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const bool binary_mode = true; const bool binary_mode = true;
const bool check_capacity = false; const bool check_capacity = false;
const bool have_extra_field = false; const bool have_extra_field = false;
const int LOOP = 10 * 1000 * 1000; const int LOOP = 10 * 1000 * 1000;
const char *data_path = "/opt/fastcfs/fdir/data";
const char *subdir_name = "binlog";
const uint32_t subdirs = 256;
int result; int result;
TestType test_type = TEST_TYPE_ITOA;
uint64_t id = 123456;
double d = 123.456;
int ch;
int i; int i;
int len;
int64_t start_time_us; int64_t start_time_us;
int convert_time_us; int append_time_us;
int sprintf_time_us; int sprintf_time_us;
double ratio; double ratio;
FastBuffer buffer; FastBuffer buffer;
DATrunkSpaceLogRecord record; DATrunkSpaceLogRecord record;
char full_filename1[PATH_MAX];
char full_filename2[PATH_MAX];
char buff[32] = {0};
char *caption = "itoa";
log_init(); log_init();
g_current_time = time(NULL); g_current_time = time(NULL);
@ -201,108 +175,53 @@ int main(int argc, char *argv[])
return result; return result;
} }
while ((ch=getopt(argc, argv, "ht:")) != -1) { memset(&record, 0, sizeof(record));
switch (ch) { record.op_type = 'C';
case 'h': record.slice_type = DA_SLICE_TYPE_FILE;
usage(argv[0]); record.storage.version = 1111;
return 0; record.oid = 9007211709265131LL;
case 't': record.fid = 0;
if (strcasecmp(optarg, "itoa") == 0) { record.storage.trunk_id = 61;
test_type = TEST_TYPE_ITOA; record.storage.length = 62;
caption = "itoa"; record.storage.offset = 12345;
} else if (strcasecmp(optarg, "ftoa") == 0) { record.storage.size = 64;
test_type = TEST_TYPE_FTOA;
caption = "ftoa";
} 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);
return EINVAL;
}
break;
default:
usage(argv[0]);
return EINVAL;
}
}
if (test_type == TEST_TYPE_APPEND) {
memset(&record, 0, sizeof(record)); const char *data_path = "/opt/fastcfs/fdir/data";
record.op_type = 'C'; const char *subdir_name = "binlog";
record.slice_type = DA_SLICE_TYPE_FILE; const uint32_t subdirs = 256;
record.storage.version = 1111; uint64_t id = 123456;
record.oid = 9007211709265131LL; char full_filename1[PATH_MAX];
record.fid = 0; char full_filename2[PATH_MAX];
record.storage.trunk_id = 61;
record.storage.length = 62;
record.storage.offset = 12345;
record.storage.size = 64;
}
start_time_us = get_current_time_us(); start_time_us = get_current_time_us();
for (i=0; i<LOOP; i++) { for (i=0; i<LOOP; i++) {
switch (test_type) { cache_binlog_filename_by_sprintf(data_path, subdir_name,
case TEST_TYPE_APPEND: subdirs, ++id, full_filename1, sizeof(full_filename1));
cache_binlog_filename_by_sprintf(data_path, subdir_name, fast_buffer_reset(&buffer);
subdirs, ++id, full_filename1, sizeof(full_filename1)); log_pack_by_sprintf(&record, &buffer, have_extra_field);
fast_buffer_reset(&buffer);
log_pack_by_sprintf(&record, &buffer, have_extra_field);
break;
case TEST_TYPE_ITOA:
sprintf(buff, "%"PRId64, id);
break;
case TEST_TYPE_FTOA:
sprintf(buff, "%.2f", d);
break;
case TEST_TYPE_INT2HEX:
sprintf(buff, "%x", (int)id);
break;
default:
break;
}
} }
sprintf_time_us = (get_current_time_us() - start_time_us); sprintf_time_us = (get_current_time_us() - start_time_us);
start_time_us = get_current_time_us(); start_time_us = get_current_time_us();
for (i=0; i<LOOP; i++) { for (i=0; i<LOOP; i++) {
switch (test_type) { cache_binlog_filename_by_append(data_path, subdir_name,
case TEST_TYPE_APPEND: subdirs, ++id, full_filename2, sizeof(full_filename2));
cache_binlog_filename_by_append(data_path, subdir_name, fast_buffer_reset(&buffer);
subdirs, ++id, full_filename2, sizeof(full_filename2)); log_pack_by_append(&record, &buffer, have_extra_field);
fast_buffer_reset(&buffer);
log_pack_by_append(&record, &buffer, have_extra_field);
break;
case TEST_TYPE_ITOA:
len = fc_itoa(id, buff);
*(buff + len) = '\0';
break;
case TEST_TYPE_FTOA:
len = fc_ftoa(d, 2, buff);
*(buff + len) = '\0';
break;
case TEST_TYPE_INT2HEX:
int2hex(id, buff, 0);
break;
default:
break;
}
} }
convert_time_us = (get_current_time_us() - start_time_us); append_time_us = (get_current_time_us() - start_time_us);
if (convert_time_us > 0) { if (append_time_us > 0) {
ratio = (double)sprintf_time_us / (double)convert_time_us; ratio = (double)sprintf_time_us / (double)append_time_us;
} else { } else {
ratio = 1.0; ratio = 1.0;
} }
printf("sprintf time: %d ms, %s time: %d ms, " printf("sprintf time: %d ms, append time: %d ms, "
"sprintf time / %s time: %d%%\n", "sprintf time / append time: %d%%\n",
sprintf_time_us / 1000, caption, convert_time_us / 1000, sprintf_time_us / 1000, append_time_us / 1000,
caption, (int)(ratio * 100.00)); (int)(ratio * 100.00));
fast_buffer_destroy(&buffer); fast_buffer_destroy(&buffer);
return 0; return 0;

View File

@ -32,7 +32,6 @@ int main(int argc, char *argv[])
int fd; int fd;
int result; int result;
int n; int n;
int i;
char buf[1024]; char buf[1024];
if (argc < 2) { if (argc < 2) {
@ -70,7 +69,7 @@ int main(int argc, char *argv[])
return errno != 0 ? errno : EIO; return errno != 0 ? errno : EIO;
} }
for (i=0; i<5; i++) { for (int i=0; i<5; i++) {
if (lseek(fd, 0, SEEK_SET) < 0) { if (lseek(fd, 0, SEEK_SET) < 0) {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"lseek file %s fail, " \ "lseek file %s fail, " \