#209 rss.c, composite.c; DBAR_EXP encodation methods; symbol NO_PNG out.gif

This commit is contained in:
gitlost 2020-12-21 19:30:07 +00:00
parent 2b85585e69
commit bee5f08f50
24 changed files with 1309 additions and 1257 deletions

View file

@ -2852,6 +2852,94 @@ static void test_fuzz(int index, int debug) {
testFinish();
}
#include <time.h>
#define TEST_PERF_ITERATIONS 1000
// Not a real test, just performance indicator
static void test_perf(int index, int debug) {
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
return;
}
int ret;
struct item {
int symbology;
int option_1;
char *data;
char *composite;
int ret;
int expected_rows;
int expected_width;
char *comment;
};
struct item data[] = {
/* 0*/ { BARCODE_EANX_CC, 1, "123456789012",
"[91]123456789012345678901234567890123456789012345678901234",
0, 11, 99, "58 chars CC-A" },
/* 1*/ { BARCODE_UPCA_CC, 2, "12345678901",
"[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[94]12345678901234567890123456789012345678901234567890",
0, 48, 99, "336 chars CC-B" },
/* 2*/ { BARCODE_GS1_128_CC, 3, "[01]12345678901231",
"[91]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[92]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[93]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[94]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[95]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
"[96]123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
0, 32, 205, "564 chars CC-C" },
};
int data_size = ARRAY_SIZE(data);
clock_t start, total_encode = 0, total_buffer = 0, diff_encode, diff_buffer;
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
diff_encode = diff_buffer = 0;
for (int j = 0; j < TEST_PERF_ITERATIONS; j++) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
int length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, data[i].option_1, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data);
int composite_length = strlen(data[i].composite);
start = clock();
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);
diff_encode += clock() - start;
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d (%s)\n", i, symbol->rows, data[i].expected_rows, data[i].data);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data);
start = clock();
ret = ZBarcode_Buffer(symbol, 0 /*rotate_angle*/);
diff_buffer += clock() - start;
assert_zero(ret, "i:%d ZBarcode_Buffer ret %d != 0 (%s)\n", i, ret, symbol->errtxt);
ZBarcode_Delete(symbol);
}
printf("%s: diff_encode %gms, diff_buffer %gms\n", data[i].comment, diff_encode * 1000.0 / CLOCKS_PER_SEC, diff_buffer * 1000.0 / CLOCKS_PER_SEC);
total_encode += diff_encode;
total_buffer += diff_buffer;
}
if (index != -1) {
printf("totals: encode %gms, buffer %gms\n", total_encode * 1000.0 / CLOCKS_PER_SEC, total_buffer * 1000.0 / CLOCKS_PER_SEC);
}
}
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
@ -2865,6 +2953,7 @@ int main(int argc, char *argv[]) {
{ "test_encodation_11", test_encodation_11, 1, 1, 1 },
{ "test_addongap", test_addongap, 1, 1, 1 },
{ "test_fuzz", test_fuzz, 1, 0, 1 },
{ "test_perf", test_perf, 1, 0, 1 },
};
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));