Python เบื้องต้นสำหรับการทดสอบโค้ด
Alexander Levin
Data Scientist
ประสิทธิภาพ (Performance) - ซอฟต์แวร์ใช้ทรัพยากรระบบเพื่อทำงานได้มีประสิทธิผลเพียงใด
การทดสอบประสิทธิภาพ (Performance Testing) - การทดสอบประเภทหนึ่งที่วัดประสิทธิภาพของซอฟต์แวร์
ทรัพยากร:
กรณีตัวอย่าง:
การติดตั้ง:
pip install pytest-benchmark
# Example_1.py
import time
def test_func(benchmark):
benchmark(time.sleep, 1)
คำสั่ง CLI:
pytest Example_1.py
ผลลัพธ์หลังรันคำสั่ง CLI:

เมื่อใช้ time.sleep(3) แทน time.sleep(1):

# Example_2.py
import time
def test_func(benchmark):
@benchmark
def sleep_for_1_sec():
time.sleep(1)
คำสั่ง CLI:
pytest Example_2.py
pytest-benchmark fixture ได้โดย:benchmark โดยตรง@benchmark เป็น decoratorPython เบื้องต้นสำหรับการทดสอบโค้ด