5

I've been testing ZBar and ZXing, I saw a lot of posts saying "ZXing is to slow", "ZBar is much faster", but I didn't saw any tests made public. I change the code to accept images from gallery and repeat the decoding of the QRCode 50 times, made a few tests, and ZXing is much faster than ZBar, but both libraries have the same strange problem, the first result was like 150 milliseconds, and all the next values are much faster, like half of the first decoding.

I was counting the time of this line in ZXing

Result res = qrreader.decode(bBitmap);

and in ZBar this one

int result = scanner.scanImage(barcode);

Does someone know why the first time it decodes the image its one result of X milliseconds, and the next times is much much faster? Is this some 'problem' (not problem, optimizations) of the libraries with image processing?

xanexpt
  • 713
  • 8
  • 20
  • I'm guessing that it has to initialize a bunch of objects the first time you execute a command, and after that it reuses them – Pontus Backlund Apr 14 '14 at 15:01
  • I thought about that, but to try to prevent that I initialize the object that have the decode in every test – xanexpt Apr 14 '14 at 15:05
  • Have you checked the source? What does it do when you do `qrreader.decode(bitmap)` or `scanner.scanImage(barCode);` ? I'm guessing it creates objects when you call those. – Pontus Backlund Apr 14 '14 at 15:11
  • yes, but I initialize the object every time, so it creates all those objects you say every time. `QRCodeReader qrreader = new QRCodeReader();` and then `Result res = qrreader.decode(bBitmap);` – xanexpt Apr 14 '14 at 15:25

1 Answers1

0

I assume you are running these tests on a desktop computer and not a phone. Regular JavaSE JVMs compile frequently-used code into native code after they have been used lot. So first runs may be slower. Also be careful that you are not measuring a bunch of other JVM initialization in your benchmark. It's best to let things 'warm up' a few iterations and then start timing.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • I'm running the tests in several smart phones, with different cpu's, I didn’t do the tests in a desktop because I need to test how they perform in mobile devices. I think I’m measuring the correct info, I will let it 'warm up' like you say, but I wanted to document the slow reading in the beginning and why that happen. – xanexpt Apr 14 '14 at 16:33
  • It could be similar effects as JVMs like Dalvik also have a JIT since Android 2.2. – Sean Owen Apr 14 '14 at 16:57
  • Sorry to ask this here but, does zxing stopped the support/updates for ios? – xanexpt Apr 15 '14 at 10:01
  • Yes it was removed from v3.0 – Sean Owen Apr 15 '14 at 10:14