@@ -221,3 +221,61 @@ def test_performance_300_items(self):
221221 print (f" Total: { execution_time + serialize_time + deserialize_time :.6f} seconds" )
222222 print ("=" * 80 )
223223
224+ def test_performance_periodic_serialization_300_items (self ):
225+ """Measure execution and periodic serialization time with 300 items."""
226+ workflow = self ._create_workflow_with_item_count (300 )
227+
228+ # Track serialization metrics
229+ serialization_checkpoints = []
230+ tasks_completed = 0
231+ checkpoint_interval = 10 # Serialize every 10 task completions
232+
233+ def did_complete_task (task ):
234+ nonlocal tasks_completed
235+ tasks_completed += 1
236+
237+ # Serialize at checkpoints
238+ if tasks_completed % checkpoint_interval == 0 :
239+ start_serialize = time .time ()
240+ state = self .serializer .to_dict (workflow )
241+ end_serialize = time .time ()
242+ serialize_time = end_serialize - start_serialize
243+
244+ serialization_checkpoints .append ({
245+ 'steps' : tasks_completed ,
246+ 'tasks' : len (workflow .tasks ),
247+ 'time' : serialize_time
248+ })
249+
250+ # Measure execution time with periodic serialization
251+ start_execution = time .time ()
252+ workflow .do_engine_steps (did_complete_task = did_complete_task )
253+ end_execution = time .time ()
254+ execution_time = end_execution - start_execution
255+
256+ # Verify workflow completed
257+ self .assertTrue (workflow .completed )
258+
259+ # Calculate summary metrics
260+ total_serialization_time = sum (cp ['time' ] for cp in serialization_checkpoints )
261+ num_serializations = len (serialization_checkpoints )
262+ avg_serialization_time = total_serialization_time / num_serializations if num_serializations > 0 else 0
263+ overhead_percentage = (total_serialization_time / execution_time * 100 ) if execution_time > 0 else 0
264+
265+ # Print results
266+ print ("\n " + "=" * 80 )
267+ print ("PERIODIC SERIALIZATION TEST (performance_test.bpmn)" )
268+ print ("=" * 80 )
269+ print (f" 300 items (serialize every { checkpoint_interval } steps):" )
270+ print (f" Execution time: { execution_time :.6f} seconds" )
271+ print (f"" )
272+ print (f" Serialization checkpoints:" )
273+ for cp in serialization_checkpoints :
274+ print (f" After { cp ['steps' ]:3d} steps ({ cp ['tasks' ]:4d} tasks): { cp ['time' ]:.6f} seconds" )
275+ print (f"" )
276+ print (f" Total serialization time: { total_serialization_time :.6f} seconds" )
277+ print (f" Serialization overhead: { overhead_percentage :.1f} % of execution time" )
278+ print (f" Number of serializations: { num_serializations } " )
279+ print (f" Average per serialization: { avg_serialization_time :.6f} seconds" )
280+ print ("=" * 80 )
281+
0 commit comments