File tree 1 file changed +19
-1
lines changed
Examples/Command/Diagnostic
1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 32
32
`IO.monoMsNow` という関数でそのときの時刻を取得し、その差を計算することで実行時間を計測することができます。これにより `#time` コマンドと同様のコマンドを自作することができます。
33
33
-/
34
34
35
- open Lean Elab Command Term Meta in
35
+ open Lean Elab Command Term Meta
36
36
37
37
elab "#my_time " stx:command : command => do
38
38
let start_time ← IO.monoMsNow
@@ -42,4 +42,22 @@ elab "#my_time " stx:command : command => do
42
42
43
43
#my_time #eval fib 32
44
44
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
+
45
63
end Time --#
You can’t perform that action at this time.
0 commit comments