[llvm-bugs] [Bug 48893] New: The performance of vector::assign is 100 times worse than that of libstdc++.

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 26 18:06:42 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48893

            Bug ID: 48893
           Summary: The performance of vector::assign is 100 times worse
                    than that of libstdc++.
           Product: libc++
           Version: 8.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: 2077213809 at qq.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Created attachment 24423
  --> https://bugs.llvm.org/attachment.cgi?id=24423&action=edit
the testcase

For details about test cases, see the attachment.

./gccO0.out
copy 1610957372.518706
copy1 1610957372.526591
7885


./clangO0.out
copy 1610957377.298682
copy1 1610957378.455563
1156881


./gccO2.out
copy 1610957396.558745
copy1 1610957396.566606
7861

./clangO2.out
copy 1610957407.81578
copy1 1610957407.179067
97489

the test function

int main(int argc, char* argv[])
{
    std::vector<uint8_t> data;
    data.resize(1024UL*1024*24);
    std::vector<uint8_t> data1;
    struct timeval tv,tv1;
    gettimeofday(&tv, NULL);
  data1.assign(data.begin(), data.end());
    gettimeofday(&tv1, NULL);
    std::cout << "copy " << tv.tv_sec <<"." << tv.tv_usec << std::endl;
    std::cout << "copy1 " << tv1.tv_sec <<"." << tv1.tv_usec << std::endl;
  std::cout << tv1.tv_sec * 1000000 + tv1.tv_usec - (tv.tv_sec*1000000 +
tv.tv_usec) << std::endl;
    return 0;
}


The main function consumed is __construct_range_forward. libcxx use the 
__construct_range_forward 
Each element is constructed using the construct method, which is constructed
using the placement new method. GCC uses std::uninitialized_copy to copy the
memory. The performance is significantly better than that of libcxx.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210127/bd6badc5/attachment-0001.html>


More information about the llvm-bugs mailing list