Insight Into Dynamsoft Barcode SDK Decoding Performance

Many enterprises like to use Dynamsoft Barcode Reader SDK due to its flexible parameter configuration and powerful decoding capability for multiple barcodes. In this article, let’s take a glimpse of the barcode SDK template and the possible way to optimize the decoding performance from a developer’s angle.

How to Configure Templates for Decoding Performance

If you have never tried Dynamsoft Barcode Reader SDK, you can have fun with the online barcode playground, simply changing the mode to compare the performance difference straightforwardly.

template for barcode decoding performance

Furthermore, if you are an expert, you can click advanced settings to adjust a bunch of parameters by yourself.

To facilitate developers, I have uploaded five useful template files to Github:

Decoding speed or decoding accuracy? You can balance the trade-off depends on specific usage scenarios.

Here is my testing image:

all barcode types

Let’s see the detection accuracy and time cost by using the different templates:

BarcodeReader.exe AllSupportedBarcodeTypes.png  license.txt  speed.json   
Total barcode(s) found: 12. Time cost: 63 ms

BarcodeReader.exe AllSupportedBarcodeTypes.png  license.txt   balanced.json
Total barcode(s) found: 13. Time cost: 140 ms

BarcodeReader.exe AllSupportedBarcodeTypes.png  license.txt   coverage.json
Total barcode(s) found: 13. Time cost: 844 ms

BarcodeReader.exe AllSupportedBarcodeTypes.png  license.txt   morecoverage.json
Total barcode(s) found: 13. Time cost: 1610 ms

BarcodeReader.exe AllSupportedBarcodeTypes.png  license.txt   mostcoverage.json
Total barcode(s) found: 13. Time cost: 3156 ms

As you can see, in my case, to guarantee both accuracy and decoding speed, the most suitable template is balance.json.

When should we use other templates? The speed template is suitable for simple scenarios with less than 2 barcodes. If your image quality is not good, to pursue detection accuracy, you can try “coverage”, “morecoverage”, and “mostcoverage” templates one by one until you find the best one.

Multi-Barcode Decoding Performance: Single Thread vs. Multi Thread

In our common sense, the time cost of decoding a single barcode should be less than the time cost of decoding multi-barcodes. So a possible optimization way of reading multiple barcodes is to create multiple worker threads for processing different barcode symbologies simultaneously.

Here is the code for decoding 1D and 2D barcodes sequentially:

barcode_decoding(buffer, size, BF_CODE_39, 1, license, config);
barcode_decoding(buffer, size, BF_QR_CODE, 1, license, config);
barcode_decoding(buffer, size, BF_PDF417, 1, license, config);
barcode_decoding(buffer, size, BF_DATAMATRIX, 1, license, config);

The total time cost is 407ms:

Thread id: 22536. Type: CODE_39
Thread id: 22536. Total barcode(s) found: 1. Time cost: 235 ms

Thread id: 22536. Type: QR_CODE
Thread id: 22536. Total barcode(s) found: 1. Time cost: 47 ms

Thread id: 22536. Type: PDF417
Thread id: 22536. Total barcode(s) found: 1. Time cost: 62 ms

Thread id: 22536. Type: DATAMATRIX
Thread id: 22536. Total barcode(s) found: 1. Time cost: 63 ms

To optimize the decoding performance, I can create four threads to do the same thing:

    int starttime = gettime();
    thread t1(barcode_decoding, buffer, size, BF_CODE_39, 1, license, config); 
    thread t2(barcode_decoding, buffer, size, BF_QR_CODE, 1, license, config);
    thread t3(barcode_decoding, buffer, size, BF_PDF417, 1, license, config);
    thread t4(barcode_decoding, buffer, size, BF_DATAMATRIX, 1, license, config);
    t1.join();
    t2.join();
    t3.join();
    t4.join();
    int endtime = gettime();
    printf("Thread time cost: %d ms\n\n", (endtime - starttime));

The final time cost is 265ms:

Thread id: 24024. Type: QR_CODE
Thread id: 24024. Total barcode(s) found: 1. Time cost: 78 ms

Thread id: 17384. Type: DATAMATRIX
Thread id: 17384. Total barcode(s) found: 1. Time cost: 78 ms

Thread id: 24264. Type: PDF417
Thread id: 24264. Total barcode(s) found: 1. Time cost: 94 ms

Thread id: 4060. Type: CODE_39
Thread id: 4060. Total barcode(s) found: 1. Time cost: 265 ms

Thread time cost: 265 ms

So far, it seems good. However, if you pass multiple barcode types to the Dynamsoft barcode decoding API, a magical thing will happen:

barcode_decoding(buffer, size, BF_CODE_39 | BF_DATAMATRIX | BF_QR_CODE | BF_PDF417, 1, license, config);

It is faster than your own multi-thread solution:

Thread id: 20308. Type: PDF417
Thread id: 20308. Type: QR_CODE
Thread id: 20308. Type: DATAMATRIX
Thread id: 20308. Type: CODE_39
Thread id: 20308. Total barcode(s) found: 4. Time cost: 250 ms

The reason is all Dynamsoft barcoding decoding APIs are implemented in threading. Therefore, you do not need to create threads for optimizing decoding performance.

Source Code

https://github.com/yushulx/cmake-cpp-barcode-qrcode-mrz