@@ -320,6 +320,51 @@ def test_save_benchmark_results_returns_remapped_data(self):
320320 }
321321 self .assertEqual (remapped_data , expected_remapped_data )
322322
323+ def test_save_benchmark_results_handles_nan (self ):
324+ df = pd .DataFrame ({
325+ "Benchmark" : ["BM_Test1" , "BM_Test2" ],
326+ "Mean_Wall_Time" : [10.0 , 20.0 ],
327+ "Mean_CPU_Time" : [11.0 , 21.0 ],
328+ "Mean_Iterations" : [100 , 200 ],
329+ "Wall_Time_std" : [1.0 , math .nan ],
330+ "CPU_Time_std" : [1.1 , math .nan ],
331+ "Iterations_std" : [10.0 , math .nan ],
332+ "cycles" : [1000 , math .nan ],
333+ "instructions" : [500 , 600 ],
334+ }).set_index ("Benchmark" )
335+
336+ reporter .SaveBenchmarkResults (self .test_dir .full_path , df )
337+ file_name = os .path .join (self .test_dir , "results.json" )
338+ self .assertTrue (os .path .exists (file_name ))
339+ with open (file_name , "r" ) as json_file :
340+ data = json .load (json_file )
341+
342+ expected_benchmarks = [
343+ {
344+ "name" : "BM_Test1" ,
345+ "real_time" : 10.0 ,
346+ "cpu_time" : 11.0 ,
347+ "iterations" : 100 ,
348+ "real_time_std" : 1.0 ,
349+ "cpu_time_std" : 1.1 ,
350+ "iterations_std" : 10.0 ,
351+ "cycles" : 1000 ,
352+ "instructions" : 500 ,
353+ },
354+ {
355+ "name" : "BM_Test2" ,
356+ "real_time" : 20.0 ,
357+ "cpu_time" : 21.0 ,
358+ "iterations" : 200 ,
359+ "real_time_std" : "NaN" ,
360+ "cpu_time_std" : "NaN" ,
361+ "iterations_std" : "NaN" ,
362+ "cycles" : "NaN" ,
363+ "instructions" : 600 ,
364+ },
365+ ]
366+ self .assertEqual (data ["benchmarks" ], expected_benchmarks )
367+
323368 def test_generate_final_report_multiple_repetitions (self ):
324369 output_dir = self .create_tempdir ()
325370 context_list = [{"key" : "value1" }, {"key" : "value2" }]
0 commit comments