TimeGuardian هي حزمة Python مصممة لقياس وتسجيل وقت التنفيذ واستخدام الذاكرة للوظائف. هذه الحزمة مفيدة بشكل خاص لمراقبة الأداء والتحسين في تطبيقات Python.
قم بتثبيت حارس الوقت مباشرة من PIP:
pip install timeguardianأو التثبيت من الكود المصدر:
cd path/to/TimeGuardian
pip install . استيراد TimeGuardian من الحزمة timeguardian واستخدامه كديكور على وظائفك لقياس وقت التنفيذ واستخدام الذاكرة.
from timeguardian import TimeGuardian
# To measure execution time and/or memory usage
@ TimeGuardian . measure
def my_function ():
# function implementation
# Custom name logging
@ TimeGuardian . measure ( name = "CustomName" )
def another_function ():
# function implementation
# Custom logging with name, time and memory
@ TimeGuardian . measure ( name = "CustomName" , elapsed = True , memory = True ) #(elapsed in ms, memory in bytes)
def another_function ():
# function implementationمراقبة الأداء مع التسجيل الشرطي:
from timeguardian import TimeGuardian
# Monitor and log only if execution time or memory usage exceeds the specified limits (time in ms, memory in bytes)
@ TimeGuardian . monitor ( elapsed = 200 , memory = 1024 )
def monitored_function ():
# function implementation تتيح لك الحزمة الزمنية لضبط الوحدات العالمية لقياسات الوقت والذاكرة. تمكنك هذه الميزة من تخصيص كيفية الإبلاغ عن وقت التنفيذ واستخدام الذاكرة.
اضبط الوحدات : استخدم TimeGuardian.set_time_unit(unit) و TimeGuardian.set_memory_unit(unit) لتعيين الوحدات العالمية لقياس الوقت والذاكرة. يجب أن تكون معلمة unit عبارة عن سلسلة تشير إلى الوحدة المطلوبة (على سبيل المثال ، "MS" للمللي ثانية ، "S" للثواني ، "البايتات" للبايت ، "KB" للكيلوبيت ، "MB" للميغابايت).
تزيين الوظائف : قم بتطبيق @TimeGuardian.measure decorator على وظائفك. سيستخدم هذا الديكور وحدات تعيين عالمي لقياس وتسجيل وقت التنفيذ واستخدام الذاكرة.
from decorators import TimeGuardian
# Set the units for time and memory measurements
TimeGuardian . set_time_unit ( 'ms' ) # Set time unit to milliseconds
TimeGuardian . set_memory_unit ( 'MB' ) # Set memory unit to megabytes
@ TimeGuardian . measure ( elapsed = True , memory = True , name = "Sample Function" )
def sample_function ():
# Function implementation
...
# Call the decorated function
sample_function () في هذا المثال ، يتم قياس sample_function وتسجيلها في مللي ثانية للوقت والميجابايت لاستخدام الذاكرة.
المساهمات في الوقت المحدد نرحب!
تم ترخيص هذا المشروع بموجب ترخيص معهد ماساتشوستس للتكنولوجيا - راجع ملف الترخيص للحصول على التفاصيل.