[Embedded C Optimization]
In IF-ELSE statements, you basically check on the IF condition. If that condition is true, the IF block will be executed and the ELSE block will be skipped. Surely, if the condition is false, the ELSE block will be executed and the IF block will be skipped.
.
You may think that, in both cases, performance is the same. Well, it's not. Otherwise, this post won't come to existence XD.
Performance-wise, it's preferable that the IF block gets executed. This is due to CPU pipeline behavior. The pipeline was firstly introduced to boost the CPU performance by fetching next instructions while the CPU is executing the current instruction. By default, the pipeline will fetch the instructions of IF block. Hence, if the IF block gets executed then all is fine. On the other hand, if the ELSE block is executed, the pipeline will be flushed and refilled with ELSE instructions.
This is why it's preferable that the IF block gets executed. So, what you should choose the IF condition such that it will be more likely to evaluate to TRUE.
Of course, there are different optimizations on compiler and hardware levels that can avoid pipeline flushing by branch prediction. However, you should just be a good player and try to do more right than wrong.
.
Hopefully, this was clear, correct and informative.
Alpha-BITs
Engineering Tutorials and Talks.
30/07/2022
جزء أساسي من عمل مهندس البرمجيات في أي مجال بما فيهم الإمبديد هو حل المسائل، و دا من الحاجات اللي بتميز مهندس البرمجيات، إنه مش بس قادر يكتب كود يقوم بوظيفة معينة، لا هو كمان قادر يلاقي الطريقة الأمثل للقيام بالوظيفة دي، أو كما يسميها أغلب الناس "خوارزميات".
.
المسائل في العادة بيكون ليها أكتر من طريقة أو خوارزمية للحل، والخوارزميات دي مش زي بعضها في الأداء، هنا يظهر سؤال مهم وهو "إزاي نعرف نفاضل ما بين الخوارزميات ونطلع بأفضل واحدة بينهم؟"
.
والاجابة ببساطة إننا بنقيس أداء الخوارزمية على محكين: الزمن ومساحة الذاكرة، وببساطة الخوازمية اللي بتاخد وقت أقل بتكون أفضل في السرعة، والخوارزمية اللي بتستهلك مساحة أقل بتكون أفضل في التوفير، وعلى حسب انا محتاج سرعة ولا محتاج توفير بأقدر أقرر هاخد مين..
.
بردو عشان تكون عارف المصطلحات، تقييم السرعة بيتم من خلال حاجة اسمها time complexity.
وبيتم تقييم استخدام المساحة عن طريق space complexity.
.
دا كان مقدمة للي عاوز اتكلم عنها انهاردة، ألا وهي الطريقة البدائية لحل المسائل، يعني أول طريقة حل بتيجي على بالك لما تقابل مسألة، وغالبا الطريقة دي بتديك أسوأ حل ممكن بس بردو في بعض الأحيان بتديك الحل الوحيد الممكن..
.
الـ bruteforcing
أو بالعربي "القوة الغاشمة" هو ببساطة إنك تتغاشم على المسألة لحد ما توصل للي انت عاوزه،
مثال:
لو إديتك مجموعة أرقام وقولتلك عاوز أكبر ناتج ضرب عن أي رقمين في المجموعة، الحل الغشيم هو إنك ببساطة تمسك كل رقم وتضربه ف كل الأرقام الباقية وتحتفظ بناتج الضرب عن كل عملية وبعدين تشوف انهي ناتج هو الأكبر، دا مثال واضح جدا على طريقة الحل الغشيمة.
.
بالرغم من عيوب حلول القوة الغاشمة اللي بيكون أداءها ضعيف لكنها بتمثل مداخل كويسة جدا لحلول أذكى وأفضل وبتنقلنا لمرحلة الحلول الغاشمة المطورة
Optimized Brute Force
.
قياسا على المثال السابق، واحد من الحلول المطورة هو إنك تستخرج أكبر رقمين، وأكيد لما أضربهم ف بعض هيدوني أكبر حاصل ضرب ممكن، كدا بكون وفرت على نفسي عمليات ضرب كتير ملهاش لازمة ومكلفة
دا اللي ممكن نتكلم عليه أكتر في منشورات قادمة إن شاء الله
31/12/2021
كل سنة .. كل مناسبة ..
02/12/2021
المشروع دا لعمل
logic analyzer and oscilloscope
بسيط وجاهز كل اللي هتحتاجة
Pico2040, USB cable, USB OTG converter and mobile phone or tablet.
لينك المشروع
https://github.com/fhdm-dev/scoppy
منقول ، لينك البوست الاصلي
https://www.linkedin.com/posts/muhammad-hanafy_%D8%A7%D9%84%D8%B3%D9%84%D8%A7%D9%85-%D8%B9%D9%84%D9%8A%D9%83%D9%85-%D9%84%D9%82%D9%8A%D8%AA-%D8%A7%D9%84%D9%85%D8%B4%D8%B1%D9%88%D8%B9-%D8%AF%D9%87-%D9%84%D8%B9%D9%85%D9%84-logic-activity-6871885271743393792-QilG
14/11/2021
Hi everyone 😊
Please meet my dear student, Ammar ❤️❤️
We started all the way together from scratch to where he could build this super cool robot.
.
Give him some applause kindly 💜
The future robot https://www.youtube.com/channel/UC3s8gSRSwknJBRzaVwhwAGwthis is the teacher i take with go sub to him and sub to me and share my vids pls
05/11/2021
Directed by CLEVE MOLER :)
29/10/2021
تاعتي 🥺🥺❤️
Click here to claim your Sponsored Listing.
Location
Category
Contact the school
Website
Address
Alexandria