A working example that compares two dataframes and measures the CPU usage during the comparison:
In this example, we have two example dataframes df
and dg
. The compare_dataframes
function compares the dataframes by using the equals
method. You can modify the comparison logic based on your specific requirements.
Before performing the comparison, the initial CPU usage is obtained using psutil.cpu_percent()
. After the comparison, the final CPU usage is obtained, and the difference in CPU usage is calculated.
Finally, the result, indicating whether the dataframes are equal, and the CPU usage difference, is printed.
Please note that the CPU usage can vary depending on the specific system specifications and the complexity of the dataframe operations being performed. This example provides a basic approach to measure CPU usage during dataframe comparison, but you may need to adjust it according to your specific use case and requirements.
Following is the result in this case. df was about 3.2Mb and dg which was using specific datatypes was about 1.5Mb.
Dataframes are equal: False CPU Usage: -1.5%
psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system monitoring, profiling, limiting process resources and the management of running processes.
https://psutil.readthedocs.io/en/latest/
No comments:
Post a Comment