J 打印状态栏和百分比

J to print out status bar and percentage

我通过

来计算处理时间
start =: 6!:0 ''

在我的代码顶部并放置

end =: (6!:0 '') - start

在我的代码末尾。但是,有什么方法可以在 J 中实现这样的状态栏吗?

[====                      ]  25%
[============              ]  50%
[==========================] 100%

谢谢!

如果我理解你的问题,你可以使用系统定义为0 0 $ 1!:2&2smoutput在屏幕上显示你的处理里程碑

someverb =: 3 : 0
   smoutput '{        }'
   code
   smoutput '{+++     }'
   more code
   smoutput '{+++++   }'
   more code
   smoutput '{++++++++}'
)

但您必须知道插入 smoutput 表达式的位置将对应于已发生的处理量。

举个例子:

   test =: 3 : 0
​smoutput 6!:0 'hh:mm:ss.sss'
​6!:3 (2) NB. 2 second delay
​smoutput 6!:0 'hh:mm:ss.sss'
​6!:3 (2) NB. 2 second delay
​smoutput 6!:0 'hh:mm:ss.sss'
​)
   test ''
14:53:42.313
14:53:44.317 NB. after two second delay
14:53:46.326 NB. after two second delay

或更接近您想要的输出

test1 =: 3 : 0
  start=. 6!:0 ''
  smoutput '[            ]   0%'
  6!:3 (2) NB. 2 second delay
  smoutput '[===         ]  25%'
  6!:3 (2) NB. 2 second delay
  smoutput '[======      ]  50%'
  6!:3 (4) NB. 4 second delay
  smoutput '[============] 100%'
  (6!:0 '')- start
)
   test1 ''
[            ]   0%
[===         ]  25%
[======      ]  50%
[============] 100%
0 0 0 0 0 8.01821