0Pricing
Mojo Academy · درس

أدوات التوقيت وقياس الأداء

قِس الأداء قبل أن تحسّنه

أدوات التوقيت وقياس الأداء درس مجاني في Mojo Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Mojo Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Mojo Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Measure Before You Optimize

Never guess where time goes. You first measure your code, because the slow part is rarely the part you expected. ⏱️

The time Module

Mojo ships a time module with helpers to read the clock. It is your simplest tool for timing a block of work.

from time import now

Reading the Clock

The now function returns the current time in nanoseconds. Capture it just before and just after the work you want to measure.

var start = now()
# ...work...
var end = now()

Computing Elapsed Time

Subtract start from end to get the elapsed nanoseconds. Divide to convert into milliseconds or seconds for readable output.

var elapsed_ns = end - start
var ms = elapsed_ns / 1_000_000

Wall Clock vs Work

Wrap only the code you care about. If you also time setup or printing, that noise hides the real compute cost you are chasing.

Use the benchmark Module

For serious numbers, Mojo offers a benchmark module that runs your code many times and reports a stable average automatically.

from benchmark import keep

Keep Results Alive

The keep function tells the compiler a value really matters. Without it, dead-code removal may delete the work you meant to time.

var r = compute()
keep(r)

Repeat for Stable Numbers

One run is noisy from caches and the OS. Running many iterations and averaging gives a number you can actually trust.

Warm Up the Code

The first run is often slow due to cold caches and startup. A short warmup you discard makes later timings reflect steady-state speed.

Pick a Meaningful Input

Tiny inputs finish too fast to measure well. Choose an input big enough that the work takes a steady, measurable amount of time.

Time Consistently

Always benchmark on the same machine with little running in the background. Stable conditions keep one run comparable to the next.

Quick Check

Think about why we time code at all.

Recap

You learned to measure first: read now from the time module, use benchmark with keep, warm up, repeat, and time steady work. 🎯

الأسئلة الشائعة

هل درس «أدوات التوقيت وقياس الأداء» مجاني؟

نعم — نص درس «أدوات التوقيت وقياس الأداء» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Mojo Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Mojo Academy 4 دروس في المجموع.

ماذا ستتعلم في «أدوات التوقيت وقياس الأداء»؟

قِس الأداء قبل أن تحسّنه تتمرن على Mojo Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Mojo Academy؟

لا تُشترط خبرة سابقة. Mojo Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «أدوات التوقيت وقياس الأداء»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Mojo Academy هذا؟

نعم. كل درس في Mojo Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. أدوات التوقيت وقياس الأداء
  2. العثور على عنق الزجاجة الحقيقي
  3. تحسين ما يهم
  4. قراءة تقرير تحليل الأداء
← العودة إلى Mojo Academy