diff --git a/src/binary_c_code_options.h b/src/binary_c_code_options.h index 60c5d5da2dcfa1fde42355911032e24eae4c2b4f..d4e5df4faa21e7b95921809a28d927d1412115a5 100644 --- a/src/binary_c_code_options.h +++ b/src/binary_c_code_options.h @@ -316,7 +316,7 @@ void Print_trace(void); * setitimer available on your system, binary_c will exit because * this is considered a bug. */ -#define TIMEOUT_SECONDS 10 +#define TIMEOUT_SECONDS 0 /* * Provide a longer timeout if using valgrind diff --git a/src/setup/version.c b/src/setup/version.c index 543e48e054812be7c334c86d6a06f4037cf6f835..26712de6e3595a82f41de6cd84a8a0613eeb7d70 100644 --- a/src/setup/version.c +++ b/src/setup/version.c @@ -6,7 +6,7 @@ #undef __HAVE_LIBBSD__ #ifdef __HAVE_LIBBSD__ #include <bsd/bsd.h> -#endif +#endif // __HAVE_LIBBSD__ static float __test_seconds(void); #include <unistd.h> @@ -426,13 +426,120 @@ void version(struct stardata_t * RESTRICT const stardata) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" long int copy = 0, move = 0; - Timeme(copy,{Swap_stardatas_with_copy(p,q)} ); + Timeme(copy,{Swap_stardatas_with_copy(p,q)}); Timeme(move,{Swap_stardatas_with_move(p,q)}); Printf("Speed of memcpy/speed of memmove = %g\n", (double)move/(double)copy); #pragma GCC diagnostic pop } + /* + * Compare speed of strcat, strlcat, sprintf, asprintf + */ +#undef strcat +#undef strncat +#undef sprintf + { +#define Random_letter ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[random () % 26]) +#define Reset_strings_12 \ + { \ + for(i=0;i<n1;i++) \ + { \ + s1[i] = Random_letter; \ + s2[i] = Random_letter; \ + } \ + s1[n1-2] = '\0'; \ + s2[n1-2] = '\0'; \ + } +#define Reset_strings_3 \ + { \ + for(i=0;i<n1;i++) \ + { \ + s3[i] = Random_letter; \ + } \ + s3[n1-2] = '\0'; \ + } + +#define Alloc_strings_12 \ + s1 = Calloc(n1+1,sizeof(char)); \ + s2 = Calloc(n1+1,sizeof(char)); +#define Alloc_strings_3 \ + s3 = Calloc((n1+1)*2,sizeof(char)); + +#define Free_strings \ + Safe_free(s1); \ + Safe_free(s2); \ + Safe_free(s3); + +#define String_Timeme(_alloc,_reset,counter,...) \ + { \ + Timeme(counter, \ + { \ + char * s1; \ + char * s2; \ + char * MAYBE_UNUSED s3; \ + Alloc_strings_12; \ + if(_alloc) \ + { \ + Alloc_strings_3; \ + } \ + if(_reset) \ + { \ + Reset_strings_12; \ + if(_alloc) \ + { \ + Reset_strings_3; \ + } \ + } \ + __VA_ARGS__; \ + Free_strings; \ + } \ + ); \ + } + + long int _overhead, _strcat, _strncat, _strlcat; + long int _sprintf, _snprintf, _asprintf; + _overhead = _strcat = _strlcat = _strncat = + _sprintf = _snprintf = _asprintf = 0; + const size_t n1 = 1000; + unsigned int i; + String_Timeme(TRUE,TRUE,_overhead,{ + /* do nothing */ + }); + String_Timeme(TRUE,TRUE,_strcat,{ + strcat(s3,s1); + }); + String_Timeme(TRUE,TRUE,_strncat,{ + strncat(s3,s1,n1*2-1); + }); + String_Timeme(TRUE,TRUE,_strlcat,{ + strlcat(s3,s1,n1*2); + }); + String_Timeme(TRUE,TRUE,_sprintf,{ + sprintf(s3,"%s%s",s1,s2); + }); + String_Timeme(TRUE,TRUE,_snprintf,{ + snprintf(s3,n1*2-1,"%s%s",s1,s2); + }); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-result" + String_Timeme(FALSE,TRUE,_asprintf,{ + ((void)asprintf(&s3,"%s%s",s1,s2)); + }); +#pragma GCC diagnostic pop + + Printf("String concatenation speed (more is better, n1 = %zu, overhead = %ld) : strcat %ld : strncat %ld : strlcat %ld : sprintf %ld : snprintf %ld : asprintf %ld\n", + n1, + _overhead, + _strcat - 1*_overhead, + _strncat - 1*_overhead, + _strlcat - 1*_overhead, + _sprintf - 1*_overhead, + _snprintf - 1*_overhead, + _asprintf - 1*_overhead); + } + /* * Compare native memcpy to other versions of memcpy * when copying stardatas @@ -645,7 +752,8 @@ void version(struct stardata_t * RESTRICT const stardata) */ Safe_free(s1); Safe_free(s2); - + Safe_free(p); + Safe_free(q); }