swebb2066 commented on PR #561:
URL: https://github.com/apache/logging-log4cxx/pull/561#issuecomment-3514917035

   Below is a python script that will generate this:
   <img width="800" height="600" alt="Appending" 
src="https://github.com/user-attachments/assets/3141ff69-8961-4161-b6a1-6e908ad87ed7";
 />
   
   
   ```
   import re
   import matplotlib.pyplot as plt
   
   input_markdown_file = 'markdown/performance.md'
   regex_pattern = [ r"Appending (.*) using (MessageBuffer), pattern: \\%m\\%n$"
                   , r"Appending (.*) using (FMT), pattern: \\%m\\%n$"
   #               , r"Appending (.*) using (MessageBuffer), pattern: 
\\%m\\%n/threads"
   #               , r"Appending (.*) using (FMT), pattern: \\%m\\%n/threads"
                   ]
   data = {'MessageBuffer': {}
            , 'FMT': {}
            }
   line_type = {'MessageBuffer': '--'
               , 'FMT': '-.'
               }
   
   # Extract the data
   title = 'Appending'
   image_file_name = 'images/Appending.png'
   
   value_regex_pattern = r" *([0-9]+) ns"
   with open(input_markdown_file, "r") as file:
       header_found = False
       separator_found = False
       for line in file:
           if header_found and separator_found:
               # A valid table data row (starts and ends with '|')
               if not (line.strip().startswith('|') and 
line.strip().endswith('|')):
                   break
               # Split the line by '|' and strip whitespace from each part
               # The first and last elements will be empty strings due to 
leading/trailing '|'
               columns = [col.strip() for col in line.split('|')]
   
               # Ensure there are enough columns to extract data (at least 3 
for Benchmark and Time)
               if len(columns) > 2:
                   value_match = re.search(value_regex_pattern, columns[2])
                   if value_match:
                       nanoseconds =value_match.group(1)
                       for r in regex_pattern:
                           benchmark_match = re.search(r, columns[1])
                           if benchmark_match:
                               formatter = benchmark_match.group(2)
                               message_type = benchmark_match.group(1)
                               data[formatter][message_type] = int(nanoseconds)
           elif " Benchmark " in line:
               header_found = True
           elif header_found and "----" in line:
               separator_found = True
           else:
               header_found = False
   
   if len(data) < 2:
       raise ValueError(f"Benchmark data not found in {input_markdown_file}")
   
   # Create the bar chart
   fig, ax = plt.subplots(figsize=(8, 6)) # Optional: set figure size
   for formatter, item_time in data.items():
       message_types = item_time.keys()
       time_values = item_time.values()
       ax.plot(message_types, time_values, label=formatter, 
linestyle=line_type[formatter])
   
   # Add chart title and axis labels
   ax.legend()
   ax.set_title(title, fontsize=14)
   ax.set_xlabel('Message content', fontsize=12)
   ax.set_ylabel('Time (ns)', fontsize=12)
   
   # Improve layout and remove top/right spines for cleaner look
   ax.spines['right'].set_visible(False)
   ax.spines['top'].set_visible(False)
   plt.tight_layout()
   
   # Save the graph as a PNG file
   plt.savefig(image_file_name)
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to