2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[GAS]GASの処理時間を調べられるようにしておきたい。

Posted at

やったこと

GASの1つの関数?で処理時間を6分を超えるとタイムアウトエラーになってしまうそうワニ🐊
今のところ自分が作っているものではそんなこともないだろうと思ってますワニですが、
いざという時の為に調べられるようにするワニ。

ソースコード

これがコードワニ🐊

GASのソース.
function myFunction() {

  // 処理や関数の頭で現在の時刻を取得する(ms)
  var funcStartTime = new Date().getTime();

  // 10ms待ち  
  sleep(10);
  
  // 処理や関数が終わったら、終了時点の時刻を取得する(ms)
  var funcEndTime = new Date().getTime();
  
  // 終了時点の時刻-開始時点の時刻を差し引いて処理時間を求める(ms)
  var funcProcessTime = funcEndTime - funcStartTime;
  
  // 処理時間をログ出力
  Logger.log(funcProcessTime);
}

function sleep(time)
{
    var startTime = new Date().getTime();

   while (true)
   {
     var elapsedTime = new Date().getTime();

     if ((elapsedTime - startTime) > time)
     { 
       break;
     }
     elapsedTime = null;
   }
}

所感

・qiitaに挙げるレベルのものかは存じませぬが、、怒られない限り載せておくワニ🐊

2
3
2

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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?