C++ Lambda??????????
???????????? ???????[ 2014/9/16 13:20:09 ] ??????????????? C++ NET
????LB??????
?????????????????????????????????????ò?????????????
????1??t =1 ???LB??
????2??t=2 ?????????
????3??t=3 ??ú???
????4??t=4???std::function??????LB
void TestLambdaFun(int t)
{
using namespace std;
vector<int> v1(10?? 1);
int x = 0;
int u = 0;
if (t == 1)
{
clock_t begin = clock();
for (int i = 0; i < 100000; ++i)
{
for_each (v1.begin()??
v1.end()??
[&x?? &u](int i){ u += i+(x++); });// Line 1
}
clock_t end = clock();
auto spent = double(end – begin) / CLOCKS_PER_SEC;
printf(“spent for type ‘%d’ is %f u is %d ”?? t?? spent?? u);
}
else if (t == 2)
{
clock_t begin = clock();
for (int i = 0; i < 100000; ++i)
{
auto _First = v1.begin();
auto _Last = v1.end();
for (; _First != _Last; ++_First)
{
u = *_First+(x++); // Line 2
}
}
clock_t end = clock();
auto spent = double(end – begin) / CLOCKS_PER_SEC;
printf(“spent for type ‘%d’ is %f u is %d ”?? t?? spent?? u);
}
else if (t == 3)
{
clock_t begin = clock();
for (int i = 0; i < 100000; ++i)
{
auto _First = v1.begin();
auto _Last = v1.end();
for (; _First != _Last; ++_First)
{
FuncAdd(u?? x?? *_First); // Line 3
}
}
clock_t end = clock();
auto spent = double(end – begin) / CLOCKS_PER_SEC;
printf(“spent for type ‘%d’ is %f u is %d ”?? t?? spent?? u);
}
else if (t == 4)
{
clock_t begin = clock();
std::function <void (int)> lbda;
for (int i = 0; i < 100000; ++i)
{
lbda = [&](int i){ u += i + (x++); };
for_each (v1.begin()?? v1.end()?? lbda); // Line 4
}
clock_t end = clock();
auto spent = double(end – begin) / CLOCKS_PER_SEC;
printf(“spent for type ‘%d’ is %f u is %d ”?? t?? spent?? u);
}
}
void FuncAdd(int &u?? int &x?? int i)
{
u = i+(x++);
}
??????????VC++ 2010?е????????
??????debug???£?t=2????????????t=1??t=3??t=4???????????????????????????inline??????
??????release???£????/Ob1???????inline????????inline?????
????t=1??t=2?????????????t=3??????3???????????????????FuncAdd inline??????????????????????????LB?????????????????????C++ lambda expression????????????????????syntax sugar???????????????“????”??
????t=4????????t=3??????????????????std::function????????????????/Ob1????????????????????????????? operator???????????“?????”?????á?????????????????LB???std::function???????????LB???????????
???????
????C++ 11 ??lambda expression?????LB?????????????inline expression?????????????£????????????????????????????д??????????????????????????????????????????????????????????????????????????LB??????LB?????????std::function????????????????????????????????inline??á?
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
??C++????????????C++ lvalue??rvalueC++11????????C++???????????????C++?е?????????????????C++?????????C++???Windows????λ??C/C++???????????????????JAVA??C??C++??????????c++??python???????????????????????????????C++???????C++?е????????C++????????????????C++ ???????????????C++?????????????????????C++????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????