パフォーマンスの欠陥
C/C++ コードのパフォーマンスに影響する欠陥
この欠陥は、C/C++ コードのパフォーマンスのボトルネックにつながりかねない問題を検出します。検出される問題には次のものがあります。
移動操作の代わりに誤ってコピーを引き起こす問題
非効率または不必要な一時変数の作成
より効率の良い代替手段がある可能性がある関数の使用
Polyspace 結果
移動操作によってスローされる可能性があります | 移動操作をスローすると、対応するコピー操作が STL コンテナーで使用される場合がある |
const のパラメーター値によって不要なデータ コピーが生じることがあります | const パラメーター値によって移動操作が禁止され、その結果より高いパフォーマンスを必要とするコピー操作が発生することがある |
const の戻り値によって不要なデータ コピーが生じることがあります | const の戻り値によって移動操作が禁止され、より高いパフォーマンスが必要なコピー操作が行われる場合がある |
const rvalue 参照パラメーターにより、不要なデータ コピーが発生する可能性があります | rvalue 参照の const の特性により、意図された移動操作が妨げられる (R2021a 以降) |
Const std::move の入力により、オブジェクト コピーの計算量が増える場合があります | Const std::move 入力は移動できないため、より計算量の多いコピー操作が行われる |
空のデストラクターによって不要なデータ コピーが生じることがあります | ユーザーが宣言した空のデストラクターによって、移動コンストラクターと移動代入演算子の自動生成が回避される |
計算量の多い 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 が使用される |
計算量の多い変数の最後の使用 | An expensive-to-copy local variable is copied in its final use instead of being moved (R2025a 以降) |
範囲ベースの for ループの反復における計算量の多いコピー | 範囲ベースの for ループのループ変数が参照されるのではなく範囲要素からコピーされるため、非効率なコードになる |
計算量の多いローカル変数のコピーです | ローカル変数が const 参照からのコピーで作成された後、変更されない (R2021a 以降) |
計算量の多いメンバー初期化 | You assign values to class members in the constructor body instead of constructing members using a member initializer list (R2023b 以降) |
計算量の多い値渡し | パラメーターのコピーの計算量が多くなる場合がある |
計算量の多い値返し | 関数が参照やポインターではなく値で大きな出力を返す |
計算量の多い 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 指定子をコンパイル時の評価用の変数または関数に使用できる |
再割り当て前の不要な構成 | 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 以降) |
計算量の多い dynamic_cast | 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 の非メンバー演算子 +() が使用されています | 追加 (または +=) メソッドがより効率的であるのに、非メンバー関数 std::string operator+() が呼び出される |
より効率的なオーバーロードの代わりに、計算量の多い std::string のメソッドを使用 | 一重引用符で囲んだ文字の代わりに、長さが既知の文字列リテラルで std::string メソッドが呼び出される (R2021a 以降) |
空の文字列リテラルに対して計算量の多い std::string を使用 | 空の文字列リテラルに対して std::string を使用する代わりに、より計算量の少ないメンバー関数 std::basic_string の呼び出しができる (R2021a 以降) |
C 標準ライブラリから計算量の多い文字列関数を使用 | String functions from the C standard library are used inefficiently (R2022a 以降) |
std::string の短縮に計算量の多い substr() を使用 | 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 長の計算が非効率的です | std::basic_string::length() を使用する代わりに std::basic_string::c_str() からの戻り値に対して文字列長関数を使用することによって文字列長が計算される |
std::endl によって不要なフラッシュが生じることがあります | std::endl がより効率的な \n の代わりに使用される |
より効率的な make_shared ではなく new または make_unique を使用 | new または make_unique を使用して shared_ptr を初期化またはリセットすると、追加のメモリ割り当てが発生する (R2021a 以降) |
std::string::c_str() または同等の string メソッドの不要な使用 | 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 |
計算量の多いコンテナーのカウント方法を使用 | The function member count() of a container is used for checking
if a key is present, leading to inefficient code (R2021b 以降) |
計算量の多いコンテナーの挿入メソッドを使用 | 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 以降) |
計算量の多いマップの大かっこ演算子を使用して、値を挿入または代入 | 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 以降) |
セットの代わりに計算量の多いマップを使用 | The key for a map is member of the object being inserted, resulting in redundant map key (R2024b 以降) |
計算量の多い論理演算です | オペランドの順序により、論理演算が両方のオペランドを評価しなければならないため非効率なコードになる (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 以降) |
不必要なパディング | struct のメンバーを再配置してアライメント要件を満たすことでメモリを節約できる場合に、この要件を満たすためのメンバーがパディングされる (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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)