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 ms | OpenCV | Armadillo | Eigen |
| 4×4 | 0.00098 | 0.00003 | 0.00002 |
| 8×8 | 0.00034 | 0.00006 | 0.00017 |
| 16×16 | 0.00048 | 0.00029 | 0.00077 |
| 32×32 | 0.00142 | 0.00208 | 0.00185 |
| 64×64 | 0.00667 | 0.00647 | 0.00688 |
| 128×128 | 0.02190 | 0.02776 | 0.03318 |
| 256×256 | 0.23900 | 0.27900 | 0.30400 |
| 512×512 | 1.04700 | 1.17600 | 1.33900 |
Normalised
| Speed up over slowest | OpenCV | Armadillo | Eigen |
| 4×4 | 1.00x | 30.53x | 44.41x |
| 8×8 | 1.00x | 5.56x | 2.02x |
| 16×16 | 1.62x | 2.66x | 1.00x |
| 32×32 | 1.46x | 1.00x | 1.12x |
| 64×64 | 1.03x | 1.06x | 1.00x |
| 128×128 | 1.52x | 1.20x | 1.00x |
| 256×256 | 1.27x | 1.09x | 1.00x |
| 512×512 | 1.28x | 1.14x | 1.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 ms | OpenCV | Armadillo | Eigen |
| 4×4 | 0.00104 | 0.00007 | 0.00030 |
| 8×8 | 0.00070 | 0.00080 | 0.00268 |
| 16×16 | 0.00402 | 0.00271 | 0.00772 |
| 32×32 | 0.02059 | 0.02104 | 0.02527 |
| 64×64 | 0.14835 | 0.18493 | 0.06987 |
| 128×128 | 1.83967 | 1.10590 | 0.60047 |
| 256×256 | 15.54500 | 9.18000 | 2.65200 |
| 512×512 | 133.32800 | 35.43100 | 21.53300 |
Normalised
| Speed up over slowest | OpenCV | Armadillo | Eigen |
| 4×4 | 1.00x | 16.03x | 3.52x |
| 8×8 | 3.84x | 3.35x | 1.00x |
| 16×16 | 1.92x | 2.84x | 1.00x |
| 32×32 | 1.23x | 1.20x | 1.00x |
| 64×64 | 1.25x | 1.00x | 2.65x |
| 128×128 | 1.00x | 1.66x | 3.06x |
| 256×256 | 1.00x | 1.69x | 5.86x |
| 512×512 | 1.00x | 3.76x | 6.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 ms | OpenCV | Armadillo | Eigen |
| 4×4 | 0.00029 | 0.00002 | 0.00002 |
| 8×8 | 0.00024 | 0.00007 | 0.00009 |
| 16×16 | 0.00034 | 0.00019 | 0.00028 |
| 32×32 | 0.00071 | 0.00088 | 0.00111 |
| 64×64 | 0.00458 | 0.00591 | 0.00573 |
| 128×128 | 0.01636 | 0.13390 | 0.04576 |
| 256×256 | 0.12200 | 0.77400 | 0.32400 |
| 512×512 | 0.68700 | 3.44700 | 1.17600 |
Normalised
| Speed up over slowest | OpenCV | Armadillo | Eigen |
| 4×4 | 1.00x | 17.00x | 12.57x |
| 8×8 | 1.00x | 3.45x | 2.82x |
| 16×16 | 1.00x | 1.81x | 1.20x |
| 32×32 | 1.56x | 1.26x | 1.00x |
| 64×64 | 1.29x | 1.00x | 1.03x |
| 128×128 | 8.18x | 1.00x | 2.93x |
| 256×256 | 6.34x | 1.00x | 2.39x |
| 512×512 | 5.02x | 1.00x | 2.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 ms | OpenCV | Armadillo | Eigen |
| 4×4 | 0.00189 | 0.00018 | 0.00090 |
| 8×8 | 0.00198 | 0.00414 | 0.00271 |
| 16×16 | 0.01118 | 0.01315 | 0.01149 |
| 32×32 | 0.06602 | 0.05445 | 0.05464 |
| 64×64 | 0.42008 | 0.32378 | 0.30324 |
| 128×128 | 3.67776 | 4.52664 | 2.35105 |
| 256×256 | 35.45200 | 16.41900 | 17.12700 |
| 512×512 | 302.33500 | 122.48600 | 97.62200 |
Normalised
| Speed up over slowest | OpenCV | Armadillo | Eigen |
| 4×4 | 1.00x | 10.22x | 2.09x |
| 8×8 | 2.09x | 1.00x | 1.53x |
| 16×16 | 1.18x | 1.00x | 1.15x |
| 32×32 | 1.00x | 1.21x | 1.21x |
| 64×64 | 1.00x | 1.30x | 1.39x |
| 128×128 | 1.23x | 1.00x | 1.93x |
| 256×256 | 1.00x | 2.16x | 2.07x |
| 512×512 | 1.00x | 2.47x | 3.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 ms | OpenCV | Armadillo | Eigen |
| 4×4 | 0.00815 | 0.01752 | 0.00544 |
| 8×8 | 0.01498 | 0.05514 | 0.03522 |
| 16×16 | 0.08335 | 0.17098 | 0.21254 |
| 32×32 | 0.53363 | 0.73960 | 1.21068 |
| 64×64 | 3.51651 | 3.37326 | 6.89069 |
| 128×128 | 25.86869 | 24.34282 | 71.48941 |
| 256×256 | 293.54300 | 226.95800 | 722.12400 |
| 512×512 | 1823.72100 | 1595.14500 | 7747.46800 |
Normalised
| Speed up over slowest | OpenCV | Armadillo | Eigen |
| 4×4 | 2.15x | 1.00x | 3.22x |
| 8×8 | 3.68x | 1.00x | 1.57x |
| 16×16 | 2.55x | 1.24x | 1.00x |
| 32×32 | 2.27x | 1.64x | 1.00x |
| 64×64 | 1.96x | 2.04x | 1.00x |
| 128×128 | 2.76x | 2.94x | 1.00x |
| 256×256 | 2.46x | 3.18x | 1.00x |
| 512×512 | 4.25x | 4.86x | 1.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 ![]()
OpenCV vs. Armadillo vs. Eigen on Linux的更多相关文章
- OpenCV入门笔记(一) Linux下的安装
关于OpenCV,有中文的官方站点.里面翻译了官网的教程和API等.中文官方Tutorials见这里:[Tutorials] 一.Ubuntu下的安装 能够选择直接从库里安装,或者手动编译安装,请參考 ...
- ubuntu 16.04 上编译和安装C++机器学习工具包mlpack并编写mlpack-config.cmake | tutorial to compile and install mplack on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/1cd6a04d/,欢迎阅读最新内容! tutorial to compile and install mplack on ubun ...
- OpenCV2学习笔记01:Linux下OpenCV开发环境的搭建
个人已经厌倦了Windows下的开发方式,于是决定转到Linux平台上来,当然我也知道这个转变会很艰辛,但是我还是要坚持.所以,后面的所有开发我都会基于Linux和Qt,先从开发环境的搭建开始做起,当 ...
- opencv Installation in Linux and hello world
http://opencv.org/quickstart.html Installation in Linux These steps have been tested for Ubuntu 10.0 ...
- Qt Opencv 在Linux下摄像头简单示例(转)
下面写的文章也许网上也有类似的,但是大多数都没有给出思路及背景,让初学者每次都只能学到一点皮毛,不少知识需要大量搜索零碎地拼凑起来.题外话,虽然现在是碎片化信息时代,但正是这样信息整合能力也显得非常重 ...
- linux源码编译安装OpenCV
为了尽可能保证OpenCV的特性,使用OpenCV源码编译安装在linux上.先从安装其依赖项开始,以ubuntu 14.04.X为例讲解在Linux上源码编译安装OpenCV,其他linux版本可以 ...
- Ubuntu下编译安装OpenCV 2.4.7并读取摄像头[转]
主要参考: 1.http://www.ozbotz.org/opencv-installation/ 2.http://www.ozbotz.org/opencv-install-troublesho ...
- Linux下配置OpenCV1.0环境
自己一直嚷嚷着打算学学图像识别,识别个简单的,车牌号,验证码之类的,之前查过资料,OpenCV可以实现.昨天花了一个下午终于配置好环境了,今天写下总结. OpenCV这一名称包含了Open和Compu ...
- opencv 61篇
(一)--安装配置.第一个程序 标签: imagebuildincludeinputpathcmd 2011-10-21 16:16 41132人阅读 评论(50) 收藏 举报 分类: OpenCV ...
随机推荐
- 百度站长平台HTTPS认证所遇到的坑
坑1: 百度站长平台https认证失败,提示:请确保您网站的所有链接均支持https访问,且未使用不安全协议(如:SSL2.SSL3等协议). 解决办法: 1. 友情链接检查, 要检查所有的友情链接 ...
- 【maven】测试
针对spring-boot项目 通过命令行执行mvn命令来启动测试模块. 1.引入plugin 并自定义参数ignore.test 2.命令行传递参数启动test mvn clean package ...
- Ajax异步后台加载Html绑定不上事件
因项目需要,需要实时从后台动态加载html,开发过程中,遇到事件绑定不上,后来百度一番,大概意思:ajax是异步加载的,页面一开始绑定事件的时候,后台数据还没有传过来,就绑定事件,这个时候找不到这个d ...
- Git 分支代码管理日记备注
1〉 Bithucket 创建代码库 2〉 下载克隆代码 Git clone 代码链接 3〉 代码初始化完成之后,切换到代码文件夹 cd 文件夹名 4〉 查看分支情况 Git brach 5〉 ...
- SAP MM 同一个序列号可以被多次用在交货单发货过账?
SAP MM 同一个序列号可以被多次用在交货单发货过账? 如下公司间转储订单,从公司代码CSAS转入公司代码HKCS, 物料有启用序列号管理. 转储数量为5 PC.该STO单据共计有2个外向交货单 8 ...
- Context都没弄明白,还怎么做Android开发
转载:https://www.jianshu.com/p/94e0f9ab3f1d Activity mActivity =new Activity() 作为Android开发者,不知道你有没有思考过 ...
- leetcode - 括号字符串是否有效
括号字符串是否有效 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. ...
- [20190507]sga_target=0注意修改_kghdsidx_count设置.txt
[20190507]sga_target=0注意修改_kghdsidx_count设置.txt --//昨天遇到一例视图定义太复杂导致长时间分析sql语句出现library cache lock等待事 ...
- mycat原理及分表分库入门
1.什么是MyCat: MyCat是一个开源的分布式数据库系统,是一个实现了MySQL协议的服务器,前端用户可以把它看作是一个数据库代理,用MySQL客户端工具和命令行访问,而其后端可以用MySQL原 ...
- Oracle 11g R2 Sample Schemas 安装
最近准备对之前学习SQL*Loader的笔记进行整理,希望通过官方文档中的示例学习(Case Studies)来进行,但是官方文档中示例学习相关的脚本文件在数据库软件安装完成之后默认并没有提供,而是整 ...