LoginSignup
4
5

More than 5 years have passed since last update.

ダフズデバイルによるループ処理の高速化

Last updated at Posted at 2012-03-16

配列長に対する(時間)計算量は変わらないが, ループの終了のための比較回数が小さくなるため, 高速化されるらしい.

DuffsDevice.js
var iterations = items.length % 8;
var i = items.length - 1;
while (iterations) {
    process(items[i--]);
    iterations--;
}

iterations = Math.floor(items.length / 8);
while (iterations) {
    process(items[i--]);
    process(items[i--]);
    process(items[i--]);
    process(items[i--]);
    process(items[i--]);
    process(items[i--]);
    process(items[i--]);
    process(items[i--]);
    iterations--;
}
4
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5