3434# create a Reference to `id`. This will be a different value on each engine
3535ref = ipp .Reference ('id' )
3636print ("sleeping for `id` seconds on each engine" )
37- tic = time .time ()
37+ tic = time .perf_counter ()
3838ar = dv .apply (time .sleep , ref )
3939for i , r in enumerate (ar ):
40- print ("%i: %.3f" % ( i , time .time () - tic ) )
40+ print (f" { i } : { time .perf_counter () - tic :.3f } " )
4141
4242
4343def sleep_here (t ):
@@ -50,22 +50,22 @@ def sleep_here(t):
5050# one call per task
5151print ("running with one call per task" )
5252amr = v .map (sleep_here , [0.01 * t for t in range (100 )])
53- tic = time .time ()
53+ tic = time .perf_counter ()
5454for i , r in enumerate (amr ):
55- print ("task %i on engine %i: %.3f" % ( i , r [0 ], time .time () - tic ) )
55+ print (f "task { i } on engine { r [0 ]} : { time .perf_counter () - tic :.3f } " )
5656
5757print ("running with four calls per task" )
5858# with chunksize, we can have four calls per task
5959amr = v .map (sleep_here , [0.01 * t for t in range (100 )], chunksize = 4 )
60- tic = time .time ()
60+ tic = time .perf_counter ()
6161for i , r in enumerate (amr ):
62- print ("task %i on engine %i: %.3f" % ( i , r [0 ], time .time () - tic ) )
62+ print (f "task { i } on engine { r [0 ]} : { time .perf_counter () - tic :.3f } " )
6363
6464print ("running with two calls per task, with unordered results" )
6565# We can even iterate through faster results first, with ordered=False
6666amr = v .map (
6767 sleep_here , [0.01 * t for t in range (100 , 0 , - 1 )], ordered = False , chunksize = 2
6868)
69- tic = time .time ()
69+ tic = time .perf_counter ()
7070for i , r in enumerate (amr ):
71- print ("slept %.2fs on engine %i: %.3f" % ( r [ 1 ], r [ 0 ], time .time () - tic ) )
71+ print (f "slept { r [ 1 ]:.2f } s on engine { r [ 0 ] } : { time .perf_counter () - tic :.3f } " )
0 commit comments