Monitoring the progress of a calculation over a list
Here's a solution using ResourceFunction["MonitorProgress"]
:
fun[x_] := (Pause@1(*some long computation *);x^2)
ResourceFunction["MonitorProgress"][fun /@ Range@5]
(* {1, 4, 9, 16, 25} *)
You can add Print[]
, PrintTemporary[]
or Echo[]
to your function definition.
ClearAll[fun] ;
fun[x_] := (Pause[1]; Echo[x] ; x)
list = Range[10] ;
Map[fun,list]
ClearAll[fun] ;
fun[x_] := (Pause[1]; PrintTemporary[x] ; x)
list = Range[10] ;
Map[fun,list]
Also Dynamic[]
and Monitor[]
can be used:
ClearAll[fun] ;
fun[x_] := (Pause[1]; Dynamic[count] ; count++ ; x)
count = 1 ;
list = Range[10] ;
Monitor[Map[fun,list],ProgressIndicator[count,{1, Length[list]}]]