0Pricing
Mojo Academy · درس

كتابة اختبار أداء منصف

قِس المهمة نفسها في اللغتين

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

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

Why Benchmark at All?

To prove Mojo is faster, you measure it. A benchmark times the exact same task in both languages so the numbers actually mean something. 📊

Same Task, Both Sides

A fair test runs identical work in Python and Mojo. If the algorithms differ, you compare ideas, not languages, and the result is meaningless.

Pick One Workload

Choose a single, clear workload, like summing a million numbers. A focused task is easy to repeat and easy to reason about.

fn sum_to(n: Int) -> Int:
    var total = 0
    for i in range(n):
        total += i
    return total

Time the Work, Not Setup

Start the clock right before the work and stop it right after. Timing file loading or imports hides the real compute cost.

from time import now
var start = now()

Measure Elapsed Time

Subtract the start from the end to get elapsed time. That single number is what you will compare across the two languages.

var start = now()
# ...work...
var elapsed = now() - start

Run It Many Times

One run can be noisy. Repeat the task many times and average, so a random hiccup does not decide your result.

for trial in range(10):
    var t = now()
    sum_to(1_000_000)

Warm Up First

The first run is often slow due to caching and startup. Do a quick warmup run and ignore it before timing for real.

Use a Big Enough Input

Tiny inputs finish too fast to measure. Pick an input large enough that the work takes a meaningful, steady amount of time.

Avoid Dead-Code Removal

If a result is never used, the compiler may delete the work. Print or keep the output so the timed code actually runs.

var r = sum_to(1_000_000)
print(r)

Same Machine, Same Conditions

Run both versions on the same machine with nothing heavy in the background. Different hardware ruins any comparison.

Report It Clearly

Write down the input size, number of runs, and the average time. A clear report lets anyone trust and repeat your benchmark.

Quick Check

Think about what makes a comparison trustworthy.

Recap

A fair benchmark times the same work on the same machine, warms up, repeats, and reports clearly. Now the speedup you measure is real. 🎯

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

هل درس «كتابة اختبار أداء منصف» مجاني؟

نعم — نص درس «كتابة اختبار أداء منصف» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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. لماذا تسرّع fn والأنواع التنفيذ
  3. قراءة الأرقام بموضوعية
  4. عادات Mojo الاصطلاحية
← العودة إلى Mojo Academy