性能缺陷
影响 C/C++ 代码性能的缺陷
这些缺陷检测 C/C++ 代码中可能会导致出现性能瓶颈的问题。检测的问题包括:
无意中导致系统执行复制而非原本的移动操作的问题
低效或不必要的临时变量创建
使用的函数可能有更高效的替代方案
Polyspace 结果
移动运算可能抛出异常 | Throwing move operations might result in STL containers using the corresponding copy operations |
常量参数值可能导致不必要的数据副本 | Const parameter values may prevent a move operation resulting in a more performance-intensive copy operation |
常量返回值可能导致不必要的数据副本 | Const return values may prevent a move operation resulting in a more performance-intensive copy operation |
常量 rvalue 引用参数可能导致不必要的数据副本 | The const -ness of an rvalue reference prevents intended move
operation (自 R2021a 起) |
常量 std::move 输入可能导致更高成本的对象副本 | Const std::move input cannot be moved and results in more
expensive copy operation |
空析构函数可能导致不必要的数据副本 | User-declared empty destructors prevent autogeneration of move constructors and move assignment operators |
高成本返回 const 对象 | The return statement of a function copies an objects instead of moving it because
the returned object is declared as a const (自 R2022a 起) |
移动运算使用复制 | Non-const rvalue reference parameter of a function or operator is
copied instead of moved (自 R2021b 起) |
对不可移动类型调用 std::move | std::move used on a class type with no move constructor or move
assignment operator |
变量的最后一次使用成本高 | An expensive-to-copy local variable is copied in its final use instead of being moved (自 R2025a 起) |
基于范围的 for 循环迭代中的高成本复制 | The loop variable of a range-based for loop is copied from the
range elements instead of being referenced resulting in inefficient code |
高成本局部变量复制 | Local variable is created by copy from a const reference and not
modified later (自 R2021a 起) |
成员初始化的成本很高 | You assign values to class members in the constructor body instead of constructing members using a member initializer list (自 R2023b 起) |
高成本的按值传递 | Parameter might be expensive to copy |
高成本的按值返回 | Functions return large output by value instead of by reference or pointer |
使用 std::any_cast 的成本很高 | An object is cast by-value using std::any_cast when casting
by-reference is more efficient (自 R2023b 起) |
从常量字符串进行高成本的 std::string 或 std::regex 构造 | A constant std::string or std::regex object is
constructed from constant data, resulting in inefficient code |
缺失 constexpr 设定符 | constexpr specifier can be used on variable or function for
compile-time evaluation |
在重新分配前执行不必要的构造 | Instead of directly constructing objects with value, you construct objects and then immediately assign values to objects (自 R2023a 起) |
高成本的未使用对象 | Expensive local object is constructed but not used (自 R2024a 起) |
高成本 std::function 的类型定义 | Definition of std::function type uses pass-by-value semantics
for arguments that are expensive to copy (自 R2024a 起) |
高成本动态强制转换 | Expensive dynamic_cast is used instead of more efficient
static_cast or const_cast (自 R2021b 起) |
高成本使用标准算法而未采用已有更高效的方法 | Functions from the algorithm library are misused with
inappropriate inputs, resulting in inefficient code (自 R2021b 起) |
高成本使用非成员 std::string operator+() 而非简单的 append 方法 | The non-member std::string operator+() function is called when
the append (or += ) method would have been more efficient |
高成本使用 std::string 方法而非更高效的重载 | An std::string method is called with a string literal of known
length, instead of a single quoted character (自 R2021a 起) |
高成本使用 std::string 处理空字符串字面值 | Use of std::string with empty string literal can be replaced by
less expensive calls to std::basic_string member functions (自 R2021a 起) |
高成本使用 C 标准库中的字符串函数 | String functions from the C standard library are used inefficiently (自 R2022a 起) |
高成本使用 substr() 缩短 std::string | The method std::string::substr() is called to shorten an
std::string object (自 R2022a 起) |
低效使用 sprintf | The function sprintf , snprintf , or
swprintf copies strings instead of the more efficient
strcpy , strncopy , or
wcsncpy (自 R2021b 起) |
字符串长度计算效率低下 | String length calculated by using string length functions on return from
std::basic_string::c_str() instead of using
std::basic_string::length() |
std::endl 可能导致不必要的刷新 | std::endl is used instead of the more efficient
\n |
使用 new 或 make_unique,而非更高效的 make_shared | Using new or make_unique to initialize or
reset shared_ptr results in additional memory allocation (自 R2021a 起) |
不必要地使用 std::string::c_str() 或等效的字符串方法 | Instead of a std::string object, a string operation uses the
C-string obtained from std::string functions including
std::string::c_str , std::string::data() ,
std::string::at() , or std::string::operator[] ,
resulting in inefficient code |
高成本使用容器的 count 方法 | The function member count() of a container is used for checking
if a key is present, leading to inefficient code (自 R2021b 起) |
高成本使用容器的 insertion 方法 | One of the insertion methods of a container is used to insert a temporary object (自 R2022a 起) |
高成本使用容器的 size 方法 | A container's size() method is used for checking emptiness
instead of its empty() method, which is more efficient (自 R2022b 起) |
高成本使用 map 的方括号运算符插入值或赋值 | The bracket operator of std::map or
std::unordered_map is used for inserting or assigning a value in the
container instead of the insert_or_assign() method, which is more
efficient (自 R2022b 起) |
缺失对容器保留方法的调用 | A fixed number of items are added to a container without calling the reserve() method of the container beforehand, resulting in inefficient code (自 R2022b 起) |
高成本使用 map 而不是使用 set | The key for a map is member of the object being inserted, resulting in redundant map key (自 R2024b 起) |
高成本逻辑运算 | A logical operation requires the evaluation of both operands because of their order, resulting in inefficient code (自 R2021a 起) |
不必要 std::move 导致高成本返回 | An unnecessary call to std::move in the return statement hinders
return value optimization, resulting in inefficient code (自 R2022b 起) |
高成本循环分配 | Fixed sized memory is allocated or deallocated in a loop (自 R2022a 起) |
高成本后增量运算 | Object is post-incremented when pre-incrementing is faster (自 R2021b 起) |
低效使用 for 循环 | Range-based for loop can perform equivalent iteration more efficiently (自 R2022a 起) |
不必要的填充 | Members of a struct are padded to fulfill alignment requirement
when rearranging the members to fulfill this requirement saves memory (自 R2021b 起) |
不必要的特殊成员函数实现 | Implementing special member functions hinders code optimization when implicit versions are equivalent (自 R2023a 起) |
对参数的不必要引用 | Parameter is passed to function as const reference when passing
by value is more efficient (自 R2024a 起) |
主题
- Bug Finder 缺陷组
Bug Finder 的缺陷检查项分为数据流、并发、数值等分组。
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)