انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهSRC-016-L02

اختبارات معيارية دقيقة (Microbenchmarks) مع JMH

  • الدرس 2 من 8
  • Senior C
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

measure small code paths without common traps.

الموضوعات المخطط لها

  • JMH (Java Microbenchmark Harness) handles warm-up, forking, and measurement iterations.
  • Traps: dead-code elimination (use a Blackhole or return values), constant folding, a loop the JIT optimizes away, shared state, unrepresentative data.
  • Run several forks and report variance, not one number.
  • Microbenchmarks answer narrow questions; confirm that the code path matters in the whole system.
تفاصيل المخطط المبدئي

عرض عملي

java
@Benchmark
public int parseTotal(Fixture f, Blackhole bh) {
    return f.parser.total(f.line);   // input from @State, result consumed
}

Use @Fork, @Warmup, @Measurement with values suited to the case; verify JMH version before recording.

اختبر فهمك

Why return or consume the result in a benchmark?

أظهر الإجابة

Otherwise the JIT may remove the computation as dead code.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.