当前位置:网站首页>Performance comparison of unaryexpr's function on matrix elements in eigen Library
Performance comparison of unaryexpr's function on matrix elements in eigen Library
2022-06-26 08:28:00 【Tonyfield】
The header function used in the test
#include <chrono>
#include <iostream>
#include <Eigen/Dense>General realization of hard limit function
/* Symmetric hard limit function
* return value : 1 if m[] > 0.0f
* -1 else
*/
Eigen::MatrixXf hardlims_slow(Eigen::MatrixXf m)
{
Eigen::MatrixXf t(m.rows(), m.cols());
for (int x = 0; x < m.rows(); x++) {
for (int y = 0; y < m.cols(); y++) {
t(x, y) = (m(x, y) > 0.0f) ? 1.0f : -1.0f;
}
}
return t;
}Hard limit function UnaryExpr Realization
Eigen::MatrixXf hardlims(Eigen::MatrixXf m)
{
return m.unaryExpr([](double x) { return 2.0f*(x >= 0.0f) - 1.0f; });
}Here is the test code snippet
auto t1 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
for (int i = 0; i < 1000000; i++)
{
m4f_hardlim = hardlims_slow(m4f);
}
auto t2 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
auto d1 = t2-t1;
std::cout << "duration 1 : " << d1 << std::endl;
for (int i = 0; i < 1000000; i++)
{
m4f_hardlim = hardlims(m4f);
}
auto t3 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
auto d2 = t3 - t2;
std::cout << "duration 2 : " << d2 << std::endl;The test results are as follows
duration 1 : 24998521
duration 2 : 10431488
Generally, it takes about... To realize one million operations 25 second ,UnaryExpr Implementation time is about 10.4 second .
边栏推荐
- 51 MCU project design: Based on 51 MCU clock perpetual calendar
- [untitled]
- Reflection example of ads2020 simulation signal
- Using transformers of hugging face to realize text classification
- (5) Matrix key
- Stream analysis of hevc learning
- Method of measuring ripple of switching power supply
- 教你几招:30句哄女孩的“霸道”温馨话,不看后悔!
- Idea auto Guide
- 1GHz active probe DIY
猜你喜欢

Relationship extraction --tplinker

Uni app installation and project directory (hbuilder configuration)

加密的JS代码,变量名能破解还原吗?

2020-10-17

Diode voltage doubling circuit

Design of reverse five times voltage amplifier circuit

(2) Buzzer

Discrete device ~ resistance capacitance

opencv學習筆記三

Stream analysis of hevc learning
随机推荐
OpenCV Learning notes iii
Microcontroller from entry to advanced
Solve the problem that pychar's terminal cannot enter the venv environment
I Summary Preface
Detailed explanation of SOC multi-core startup process
Go language shallow copy and deep copy
Can the encrypted JS code and variable name be cracked and restored?
Wechat applet beginner level chapter
Crawler case 1: JS reversely obtains HD Wallpapers of minimalist Wallpapers
XXL job configuration alarm email notification
JWT in go
Go语言浅拷贝与深拷贝
Stream analysis of hevc learning
loading view时,后面所有东西屏蔽
Undefined symbols for architecture i386与第三方编译的静态库有关
Fabrication of modulation and demodulation circuit
Relevant knowledge of DRF
Cause analysis of serial communication overshoot and method of termination
Deploy wiki system Wiki in kubesphere JS and enable Chinese full-text retrieval
Idea automatically sets author information and date