OpenCV vs. Armadillo vs. Eigen on Linux

OpenCV vs. Armadillo vs. Eigen on Linux

From:http://nghiaho.com/?p=936

In this post I’ll be comparing 3 popular C++ matrix libraries found on Linux.

OpenCV is a large computer vision library with matrix support. Armadillo wraps around LAPACK. Eigen is an interesting library, all the implementation is in the C++ header, much like boost. So it is simple to link into, but takes more time compile.

The 5 matrix operations I’ll be focusing on are: add, multiply, transpose, inversion, SVD. These are the most common functions I use. All the libraries are open source and run on a variety of platforms but I’ll just be comparing them on Ubuntu Linux.

Each of the 5 operations were tested on randomly generated matrices of different size NxN with the average running time recorded.

I was tossing up whether to use a bar chart to display the result but the results span over a very large interval. A log graph would show all the data easily but make numerical comparisons harder. So in the end I opted to show the raw data plus a normalised version to compare relative speed ups. Values highlight in red indicate the best results.

Add

Performing C = A + B

Raw data

Results in msOpenCVArmadilloEigen
4×40.000980.000030.00002
8×80.000340.000060.00017
16×160.000480.000290.00077
32×320.001420.002080.00185
64×640.006670.006470.00688
128×1280.021900.027760.03318
256×2560.239000.279000.30400
512×5121.047001.176001.33900

Normalised

Speed up over slowestOpenCVArmadilloEigen
4×41.00x30.53x44.41x
8×81.00x5.56x2.02x
16×161.62x2.66x1.00x
32×321.46x1.00x1.12x
64×641.03x1.06x1.00x
128×1281.52x1.20x1.00x
256×2561.27x1.09x1.00x
512×5121.28x1.14x1.00x

The average running time for all 3 libraries are very similar so I would say there is no clear winner here. In the 4×4 case where OpenCV is much slower it might be due to overhead in error checking.


Multiply

Performing C = A * B

Raw data

Results in msOpenCVArmadilloEigen
4×40.001040.000070.00030
8×80.000700.000800.00268
16×160.004020.002710.00772
32×320.020590.021040.02527
64×640.148350.184930.06987
128×1281.839671.105900.60047
256×25615.545009.180002.65200
512×512133.3280035.4310021.53300

Normalised

Speed up over slowestOpenCVArmadilloEigen
4×41.00x16.03x3.52x
8×83.84x3.35x1.00x
16×161.92x2.84x1.00x
32×321.23x1.20x1.00x
64×641.25x1.00x2.65x
128×1281.00x1.66x3.06x
256×2561.00x1.69x5.86x
512×5121.00x3.76x6.19x

Average running time for all 3 are similar up to 64×64, where Eigen comes out as the clear winner.


Transpose

Performing C = A^T.

Raw data

Results in msOpenCVArmadilloEigen
4×40.000290.000020.00002
8×80.000240.000070.00009
16×160.000340.000190.00028
32×320.000710.000880.00111
64×640.004580.005910.00573
128×1280.016360.133900.04576
256×2560.122000.774000.32400
512×5120.687003.447001.17600

Normalised

Speed up over slowestOpenCVArmadilloEigen
4×41.00x17.00x12.57x
8×81.00x3.45x2.82x
16×161.00x1.81x1.20x
32×321.56x1.26x1.00x
64×641.29x1.00x1.03x
128×1288.18x1.00x2.93x
256×2566.34x1.00x2.39x
512×5125.02x1.00x2.93x

Comparable running time up to 64×64, after which OpenCV is the winner by quite a bit. Some clever memory manipulation?


Inversion

Performing C = A^-1

Raw data

Results in msOpenCVArmadilloEigen
4×40.001890.000180.00090
8×80.001980.004140.00271
16×160.011180.013150.01149
32×320.066020.054450.05464
64×640.420080.323780.30324
128×1283.677764.526642.35105
256×25635.4520016.4190017.12700
512×512302.33500122.4860097.62200

Normalised

Speed up over slowestOpenCVArmadilloEigen
4×41.00x10.22x2.09x
8×82.09x1.00x1.53x
16×161.18x1.00x1.15x
32×321.00x1.21x1.21x
64×641.00x1.30x1.39x
128×1281.23x1.00x1.93x
256×2561.00x2.16x2.07x
512×5121.00x2.47x3.10x

Some mix results up until 128×128, where Eigen appears to be better choice.


SVD

Performing [U,S,V] = SVD(A)

Raw data

Results in msOpenCVArmadilloEigen
4×40.008150.017520.00544
8×80.014980.055140.03522
16×160.083350.170980.21254
32×320.533630.739601.21068
64×643.516513.373266.89069
128×12825.8686924.3428271.48941
256×256293.54300226.95800722.12400
512×5121823.721001595.145007747.46800

Normalised

Speed up over slowestOpenCVArmadilloEigen
4×42.15x1.00x3.22x
8×83.68x1.00x1.57x
16×162.55x1.24x1.00x
32×322.27x1.64x1.00x
64×641.96x2.04x1.00x
128×1282.76x2.94x1.00x
256×2562.46x3.18x1.00x
512×5124.25x4.86x1.00x

Looks like OpenCV and Armadillo are the winners, depending on the size of the matrix.

Discussion

With mix results left, right and centre it is hard to come to any definite conclusion. The benchmark itself is very simple. I only focused on square matrices  of power of two, comparing execution speed, not accuracy, which is important for SVD.

What’s interesting from the benchmark is the clear difference in speed for some of the operations depending on the matrix size. Since the margins can be large it can have a noticeable impact on your application’s running time. It would be pretty cool if there was a matrix library that could switch between different algorithms depending on the size/operation requested, fine tuned to the machine it is running on. Sort of like what Atlas/Blas does.

So which library is faster? I have no idea, try them all for your application and see :)

 

转载于:https://www.cnblogs.com/cslxiao/p/3512976.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值