Skip to content

Commit 52cfe26

Browse files
authored
Merge pull request #519 from lean-ja/Seasawher/issue249
feat:「この処理は ... ミリ秒以内に終わる」という性能テストを書く
2 parents ba6bd95 + 935ce86 commit 52cfe26

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Examples/Command/Diagnostic/Time.lean

+19-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ where
3232
`IO.monoMsNow` という関数でそのときの時刻を取得し、その差を計算することで実行時間を計測することができます。これにより `#time` コマンドと同様のコマンドを自作することができます。
3333
-/
3434

35-
open Lean Elab Command Term Meta in
35+
open Lean Elab Command Term Meta
3636

3737
elab "#my_time " stx:command : command => do
3838
let start_time ← IO.monoMsNow
@@ -42,4 +42,22 @@ elab "#my_time " stx:command : command => do
4242

4343
#my_time #eval fib 32
4444

45+
/- また、派生コマンドを作ることもできます。次に挙げるのは「コマンドが1秒以内に終了するか」を検証するコマンドを自作する例です。-/
46+
47+
elab "#in_second " stx:command : command => do
48+
let start_time ← IO.monoMsNow
49+
elabCommand stx
50+
let end_time ← IO.monoMsNow
51+
let time := end_time - start_time
52+
if time <= 1000 then
53+
logInfo m!"time: {time}ms"
54+
else
55+
throwError m!"It took more than one second for the command to run."
56+
57+
-- 1秒以内に終わる
58+
#in_second #eval fib 32
59+
60+
/-- error: It took more than one second for the command to run. -/
61+
#guard_msgs (error) in #in_second #eval fibonacci 32
62+
4563
end Time --#

0 commit comments

Comments
 (0)