【統合版】不要なexecuteと「at @s」は遅くなるのか?

スポンサーリンク

結論

不要なexecuteは遅くなるのか?
→ 遅くなる

不要な「at @s」は遅くなるのか
→ 遅くなる

処理速度の速い順
素のコマンド < +不要なexecute < +不要な「at @s」

スピードテストの概要

ScriptAPIの runCommand() を使用して、コマンド(10000回分)の実行速度を計測し、比較する。
実行するコマンドは以下の3種類。

  1. 素のコマンド
    /tag @a add test
  2. +不要なexecute
    /execute as @a run tag @s add test
  3. +不要な「at @s」
    /execute as @a at @s run tag @s add test

結果

1回目
① 素のコマンド   : 139 ms
② 不要なexecute : 302 ms
③ 不要なat @s    : 416 ms

2回目
① 素のコマンド   : 143 ms
② 不要なexecute : 288 ms
③ 不要なat @s    : 409 ms

処理速度は、素のコマンドが最も速く、executeは遅くなり、「at @s」はさらに遅い。

結論

不要なexecuteは遅くなるのか?→ 遅くなる
不要な「at @s」は遅くなるのか?→ 遅くなる

処理速度の速い順
素のコマンド < +不要なexecute < +不要な「at @s」

検証用コード

import { system, world } from '@minecraft/server';

/**
 * @param {() => any} callback
 * @param {number} count
 * @returns {number}
 */
function benchmark(callback, count) {
  const start = Date.now();

  for (let i = 0; i < count; i++) {
    callback();
  }

  const end = Date.now();
  return end - start;
}

function speedTest() {
  const ow = world.getDimension('overworld');

  ow.runCommand('tag @a remove test');

  const command1 = benchmark(() => {
    ow.runCommand('tag @a add test');
  }, 10000);

  ow.runCommand('tag @a remove test');

  const command2 = benchmark(() => {
    ow.runCommand('execute as @a run tag @s add test');
  }, 10000);

  ow.runCommand('tag @a remove test');

  const command3 = benchmark(() => {
    ow.runCommand('execute as @a at @s run tag @s add test');
  }, 10000);

  world.sendMessage(`1: ${command1}ms`);
  world.sendMessage(`2: ${command2}ms`);
  world.sendMessage(`3: ${command3}ms`);
}
※投稿記事に含まれるファイルやリンクにより発生した被害についてクラフターズコロニーは責任を取りません
投稿通報

コメント

  1. めっちゃ有力な情報だこれ…

  2. なんというかそりゃそうね感w
    でも実際どのくらい遅れるか分かってよかった

コメント通報