C++ (Qt)a[i] = 44;
ASMmovl $44, 4(%esp)
xor eax, eaxret
movl %eax, (%esp,%eax,4)
ASML2: movl %ebx, 4(%esp) ; array[i] = i addl $1, %ebx ; i++ movl $LC0, (%esp) call _printf ; printf("%d\n", i) cmpl $10, %ebx ; i < 10 jne L2
C++ (Qt) #include <iostream>#include <vector>#include <array>#include <algorithm>#include <functional>#include <random>#include <chrono> template <class T = int>struct point{ typedef T pt; point(T x_ = T(), T y_ = T(), T z_ = T()):x(x_),y(y_),z(z_){} T x, y, z ;}; typedef point<double> Point3D;typedef std::array<int,3> Triangle; std::vector<Point3D> mPoint; // котейнер точекstd::vector<Triangle> mTriangle; // контейнер треугольников #define NUM_POINT (100 * 100000)#define NUM_TRIA (100 * 100000) int main(){ mPoint.resize(NUM_POINT); mTriangle.resize(NUM_TRIA); std::generate(mPoint.begin(),mPoint.end(), []()->Point3D{static typename Point3D::pt i = 0; i++; return Point3D(i,i,i);}); std::mt19937 gen; gen.seed(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())); std::uniform_int_distribution<int> dist(0, NUM_POINT - 1); std::generate(mTriangle.begin(),mTriangle.end(), [&]()->Triangle{Triangle res;for(int& i : res) {i = dist(gen);} return res;}); std::vector<int> need_del_point = {2, 12, 24, 37, 42, 55, 69, 75, 84, 93 }; std::cout<<"Need delete:"<<std::endl; for( int i : need_del_point) std::cout<<i<<" "; std::cout<<std::endl; std::sort(need_del_point.begin(),need_del_point.end()); auto print_tr = [&](const std::string& msg, size_t cnt)->void { size_t pnt_cnt = (cnt > mTriangle.size()) ? mTriangle.size() : cnt ; if(pnt_cnt) std::cout<<msg<<std::endl; for(size_t idx = 0; idx < pnt_cnt; ++idx) { std::cout<<"("<<mTriangle[idx][0]<<"," <<mTriangle[idx][1]<<"," <<mTriangle[idx][2]<<")"; if( ((idx+1) % 3) == 0 ) std::cout<<std::endl; else std::cout<<"\t"; } std::cout<<std::endl; }; print_tr("After:", 10); auto start_time = std::chrono::high_resolution_clock::now(); //std::vector<Triangle> tmp_triangle(mTriangle.size()); struct ModTriangle : public std::binary_function<Triangle,std::vector<int>,Triangle> { Triangle operator() (const Triangle& t, const std::vector<int>& del_pt) { Triangle res; for(size_t i = 0; i < t.size(); ++i) { if(std::binary_search(del_pt.begin(),del_pt.end(),t.at(i))) { res[0] = -1; break; } else { auto it = std::upper_bound(del_pt.begin(),del_pt.end(),t.at(i)); res[i] = t.at(i) - std::distance(del_pt.begin(), it); } } return res; } }; std::transform(mTriangle.begin(),mTriangle.end(),mTriangle.begin(), std::bind(ModTriangle(),std::placeholders::_1,need_del_point)); auto copy_end = std::copy_if(mTriangle.begin(),mTriangle.end(),mTriangle.begin(), [](const Triangle& t){return (t[0] >= 0);}); mTriangle.resize(std::distance(mTriangle.begin(), copy_end)); auto copy_pt_end = std::copy_if(mPoint.begin(),mPoint.end(),mPoint.begin(), [&](const Point3D& )->bool { static int i = 0; return (! std::binary_search(need_del_point.begin(), need_del_point.end(), i++)); }); mPoint.resize(std::distance(mPoint.begin(),copy_pt_end)); auto end_time = std::chrono::high_resolution_clock::now(); print_tr("Before:", 10); std::cout<<"------------------------------------------------------------------"<<std::endl; std::cout<<"deleted points = "<<NUM_POINT - mPoint.size()<<std::endl; std::cout<<"deleted triangles = "<<NUM_TRIA - mTriangle.size()<<std::endl; std::cout<<"test duration : "; std::cout << std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time).count() << "."; std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << "s."; std::cout<<std::endl; return 0;}