From d3a5b2e40d40f808ee58d340e3f4523269a52b43 Mon Sep 17 00:00:00 2001 From: ffs Upstream Date: Tue, 10 Aug 2021 13:21:35 -0400 Subject: [PATCH] ffs 2021-08-10 (2887fb48) Code extracted from: https://github.com/GTkorvo/ffs.git at commit 2887fb485b2f466124c68f29d6ae4fddaff0522e (master). Upstream Shortlog ----------------- --- ffs/ffs_conv.c | 76 +++++++++++++++++++++++++++++-------------- fm/fm_formats.c | 3 +- fm/tests/scale_test.c | 49 ++++++++++++++++++++++++---- 3 files changed, 97 insertions(+), 31 deletions(-) diff --git a/ffs/ffs_conv.c b/ffs/ffs_conv.c index 0cf92de878..2e85fbbb4c 100755 --- a/ffs/ffs_conv.c +++ b/ffs/ffs_conv.c @@ -249,6 +249,37 @@ create_default_conversion(FMField iofield, void *default_value, conv_ptr->conversions[conv_index].rc_swap = no_row_column_swap; } +/* + * differs from find_field in fm in that it includes cur_field in search shortcut + */ +static long +find_field_for_conv(char *field_name, FMFieldList fields, int cur_field, void *search_help) +{ + int i; + if (cur_field > 10) { + /* search close first */ + for (i = cur_field; i > cur_field - 10; i--) { + if (strcmp(field_name, fields[i].field_name) == 0) { + return i; + } + } + for (i = cur_field + 1; i < cur_field + 10; i++) { + if (fields[i].field_name == NULL) break; + if (strcmp(field_name, fields[i].field_name) == 0) { + return i; + } + } + } + i = 0; + while (fields[i].field_name != NULL) { + if (strcmp(field_name, fields[i].field_name) == 0) { + return i; + } + i++; + } + return -1; +} + static IOConversionPtr create_conversion(src_ioformat, target_field_list, target_struct_size, @@ -363,33 +394,30 @@ FMStructDescList target_list; field_name_strip_get_default(&nfl_sort[i], tmp_field_name, &default_val); search_name = tmp_field_name; } - while (strcmp(search_name, - input_field_list[input_index].field_name) != 0) { - input_index++; - if (input_index >= src_ioformat->body->field_count) { - if(default_val){ - if ((conv == buffer_and_convert) || - (conv == copy_dynamic_portion)) { - input_index = -1; /* Basically invalidating input_index - Indication for using default_val */ - break; - } else { - if (default_val) { - free(default_val); - default_val = NULL; - } - conv = buffer_and_convert; - if (tmp_field_name) free(tmp_field_name); - goto restart; + input_index = find_field_for_conv(search_name, input_field_list, i, NULL); + if (input_index == -1) { + if(default_val){ + if ((conv == buffer_and_convert) || + (conv == copy_dynamic_portion)) { + input_index = -1; /* Basically invalidating input_index + Indication for using default_val */ + break; + } else { + if (default_val) { + free(default_val); + default_val = NULL; } + conv = buffer_and_convert; + if (tmp_field_name) free(tmp_field_name); + goto restart; } - fprintf(stderr, - "Requested field %s missing from input format\n", - nfl_sort[i].field_name); - FFSfree_conversion(conv_ptr); - if (tmp_field_name) free(tmp_field_name); - return NULL; } + fprintf(stderr, + "Requested field %s missing from input format\n", + nfl_sort[i].field_name); + FFSfree_conversion(conv_ptr); + if (tmp_field_name) free(tmp_field_name); + return NULL; } if (tmp_field_name) free(tmp_field_name); if(input_index == -1){ diff --git a/fm/fm_formats.c b/fm/fm_formats.c index b2fb36d1bb..1dce586470 100755 --- a/fm/fm_formats.c +++ b/fm/fm_formats.c @@ -2758,7 +2758,7 @@ const char *str; return unknown_type; } -long +static long find_field(char *field_name, FMFieldList fields, int cur_field, void *search_help) { int i; @@ -2770,6 +2770,7 @@ find_field(char *field_name, FMFieldList fields, int cur_field, void *search_hel } } for (i = cur_field + 1; i < cur_field + 10; i++) { + if (fields[i].field_name == NULL) break; if (strcmp(field_name, fields[i].field_name) == 0) { return i; } diff --git a/fm/tests/scale_test.c b/fm/tests/scale_test.c index af67cd808d..dfe98965c9 100644 --- a/fm/tests/scale_test.c +++ b/fm/tests/scale_test.c @@ -5,8 +5,10 @@ #include "config.h" #include #include +#include #include "fm.h" -#include "fm_internal.h" +#include "ffs.h" + #ifdef HAVE_WINDOWS_H #include #define sleep(x) Sleep(1000*x) @@ -23,6 +25,13 @@ char *gen_name(int i) return strdup(tmp_name); } +struct base_elem { + int64_t elem_count1; + int64_t elem_count2; + int64_t *array1; + int64_t *array2; +}; + int main(argc, argv) int argc; @@ -31,12 +40,9 @@ char **argv; FMStructDescRec str_list[5]; struct timespec start, stop; - - if (argc > 1) { - } - FMContext context = create_FMcontext(NULL); - int field_count = 2000000; + FMContext context; + int field_count = 20000; field_count = ((field_count >> 2 ) << 2); // ensure field count is divisible by 4; FMFieldList list = malloc(sizeof(struct _FMField) * (field_count + 1)); int cur_count = 0; @@ -76,9 +82,40 @@ char **argv; str_list[0].struct_size = sizeof(first_rec); str_list[0].opt_info = NULL; str_list[1].format_name = NULL; + FFSContext fc = create_FFSContext(); + context = FMContext_from_FFS(fc); + FMFormat format = register_data_format(context, str_list); clock_gettime(CLOCK_MONOTONIC, &stop); double duration = (stop.tv_sec + 1.0e-9*stop.tv_nsec) - (start.tv_sec + 1.0e-9*start.tv_nsec); printf("Registration took %g seconds\n", duration); + + char * buf= malloc(sizeof(struct base_elem) * (field_count / 4)); + int i; + for (i = 0; i < field_count ; i+= 4) { + struct base_elem *tmp = (struct base_elem *) (buf + i * sizeof(int64_t)); + tmp->elem_count1 = 3; + tmp->elem_count2 = 3; + tmp->array1 = malloc(3*sizeof(tmp->array1[0])); + tmp->array2 = malloc(3*sizeof(tmp->array2[0])); + } + + clock_gettime(CLOCK_MONOTONIC, &start); + FFSBuffer b = create_FFSBuffer(); + + int buf_size; + char *encode = FFSencode(b, format, buf, &buf_size); + FFSTypeHandle th = FFSTypeHandle_from_encode(fc, encode); + clock_gettime(CLOCK_MONOTONIC, &stop); + duration = (stop.tv_sec + 1.0e-9*stop.tv_nsec) - (start.tv_sec + 1.0e-9*start.tv_nsec); + printf("encode took %g seconds\n", duration); + clock_gettime(CLOCK_MONOTONIC, &start); + establish_conversion(fc, th, str_list); + clock_gettime(CLOCK_MONOTONIC, &stop); + duration = (stop.tv_sec + 1.0e-9*stop.tv_nsec) - (start.tv_sec + 1.0e-9*start.tv_nsec); + printf("establish took %g seconds\n", duration); + } + +