def test_formatter_reuse(self): runs = 100 value1, recreate_time = StaticTimer.time_it(lambda: Formatter( "Age: @age, Domain: @email.$split('@').1, Friends: @friends.$map('index', 'name').$join" ).single(large_data[0]), runs=runs, iterations_per_run=1, display=False, log_arguments=False) f = Formatter( "Age: @age, Domain: @email.$split('@').1, Friends: @friends.$map('index', 'name').$join" ) value2, reuse_time = StaticTimer.time_it(f.single, large_data[0], runs=runs, iterations_per_run=1, display=False, log_arguments=False) print(f.single(large_data[0])) print(recreate_time / reuse_time, "x faster to reuse Formatter then recreate") self.assertEqual(value1, value2) self.assertGreater(recreate_time / reuse_time, 5)
# curve=timer.best_fit_curve(1, curve_type="Linear", transformers=len), # equation_rounding=4) # timer.plot(split_index=2, transformer=len, plot_curve=True, # curve=timer.best_fit_curve(2, curve_type="Linear", transformers=len), # equation_rounding=4) # # timer.statistics() # q = Query("friends.0.name.$split(' ').$join(': ')") # print(q.single(large_data[0])) # timer.time_it( # q.many, large_data, # iterations_per_run=1, runs=10 # ) # # q = Query("registered.$strptime.$attr('year')") # print(q.single(small_data[0])) # timer.time_it( # q.many, small_data, # iterations_per_run=50, runs=10 # ) item = {"x1": 1, "y1": 1, "x2": 12, "y2": 54} f = Formatter( "Midpoint: [@x2.$subtract(@x1).$divide(2), @y2.$subtract(@y1).$divide(2)]" ) print(f.single(item)) timer.time_it(f.single, item, iterations_per_run=10000, runs=10) timer.statistics()