当前位置:网站首页>Qvector shallow copy performance test
Qvector shallow copy performance test
2022-06-13 08:59:00 【one-rabbit】
QTime t0;
for (int i = 0; i < 100000000; ++i) {
data1.append(i);
}
//【1】 The first is appended directly to the tail
// The way 1:append
t0.start();// Start
data2.append(data1);
qDebug()<<"data2 Size "<<data2.size()<<"Append The way : Append to vector; Time is "<<t0.elapsed();
data2.clear();
// The way 2:<<
t0.restart();
data2<<data1;
qDebug()<<"data2 Size "<<data2.size()<<"<< The way : Append to vector; Time is "<<t0.elapsed();
data2.clear();
//【2】 The second replication construct And copy operators
// The way 1:qvector(&)
t0.restart();
QVector<float> data3(data1);
qDebug()<<"data2 Size "<<data3.size()<<" Copy construction ; Time is "<<t0.elapsed();
data2.clear();
// The way 2:=(&)
t0.restart();
data2=data1;
qDebug()<<"data2 Size "<<data2.size()<<" Copy operation ; Time is "<<t0.elapsed();
// Transfer parameter assignment
t0.restart();
dodo(data2);
qDebug()<<"data2 Size "<<data2.size()<<" Copy parameters ( In fact, the copy construct is called ); Time is "<<t0.elapsed();// structure
//【3】 swap In exchange for
t0.restart();
data2.swap(data1);
qDebug()<<"data2 Size "<<data2.size()<<"swap Dafa ; Time is "<<t0.elapsed();
data2.clear();
//【4】 Loop assignment Silly
t0.restart();
for (int i = 0; i < data1.size(); ++i) {
data2.append(data1.at(i));
}
qDebug()<<"data2 Size "<<data2.size()<<" Loop assignment ; Time is "<<t0.elapsed();
//【5】 Copy , Note that the target array must be kept larger than or equal to the size of the copy array
t0.restart();
memcpy(data2.begin(),data1.begin(),(size_t)sizeof(float)*data1.size()/2);
qDebug()<<"data2 Size "<<data2.size()<<" Copy memory ; Time is "<<t0.elapsed();

so use swap perhaps append And copy constructs about Shallow copy arrays are much faster .
边栏推荐
猜你喜欢

Loss outputs Nan for the Nan model

20220524 如何把CoppeliaSim安装到D盘

torch. How to calculate addmm (m, mat1, mat2)

Browser render passes

消息中间件

A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)

4、 Js-es5-i / O

useRoutes() may be used only in the context of a <Router> component.

About RSA encryption and decryption principle

20211104 为什么相似矩阵的迹相同
随机推荐
What exactly is Huawei cloud desktop saying when it says "smooth"?
transforms. ColorJitter(0.3, 0, 0, 0)
Calculation method of paging
VI editor
Docker installing MySQL local remote connection docker container MySQL
1.初步认识express
Web page H5 wechat sharing
教程篇(5.0) 04. Fortint云服务和脚本 * FortiEDR * Fortinet 网络安全专家 NSE 5
redis
Installation of sonarqube code quality management platform (to be continued)
Cesium view switching, locating, reading files, building data sources, entity control, model control, etc
【QNX Hypervisor 2.2 用户手册】4.5.1 构建QNX Guest
Gbase 8A disk problems and Solutions
关于RSA加密解密原理
Gbase 8A v95 vs v86 compression strategy analogy
20211028 Stabilizability
Sonar scan ignores the specified file
Problèmes et traitement du disque gbase 8a
20211108 微分跟踪器
如何成为白帽子黑客?我建议你从这几个阶段开始学习