SlideShare a Scribd company logo
Akhil Kaushik
Asstt. Prof., CE Deptt.,
TIT Bhiwani
Code Optimization
Optimization
• In computing, optimization is the process of modifying a
system to make some aspect of it work more efficiently or
use fewer resources.
• Ex: a computer program may be optimized so that it
executes more rapidly or is capable of operating with less
memory storage or other resources, or draw less power.
• The system may be a single computer program, a
collection of computers or even an entire network such as
the internet.
Code Optimization
• Optimization is a program transformation technique,
which tries to improve the code that consume less
resources (i.e. CPU, Memory) and deliver high speed.
• In optimization, high-level general programming
constructs are replaced by very efficient low-level
programming codes.
• Usually done at the end of the development stage since
it reduces readability & adds code that is used to
improve the performance.
Code Optimization
Optimized code’s features:-
• Executes faster
• Code size get reduced
• Efficient memory usage
• Yielding better performance
• Reduces the time and space complexity
Code Optimization
Optimizations are classified into two categories:
• Machine independent optimizations - improve target
code without taking properties of target machine into
consideration.
• Machine dependent optimization - improve target
code by checking properties of target machine.
Code Optimization
Criteria for Optimization:-
• An optimization must preserve the meaning of a
program:
-Cannot change the output produced for any input.
-Can not introduce an error.
• Optimization should, on average, speed up programs.
• Optimization should itself be fast and should not delay
the overall compiling process.
Code Optimization
Optimization can occur at several levels:
1.Design level:- At the highest level, the design may be
optimized to make best use of the available resources.
– The implementation of this design will benefit from the use of
suitable efficient algorithms and the implementation of these
algorithms will benefit from writing good quality code.
2.Compile level:- Use of an optimizing compiler tends to
ensure that the executable program is optimized at least as
much as the compiler can predict
Code Optimization
Improvements can be made at various phases:-
• Source Code: Algorithm's transformation can produce
spectacular improvements
• Intermediate Code: Compiler can improve loops,
procedure calls and address calculations.
-Typically only optimizing compilers include this phase
• Target Code: Compilers can use registers efficiently
Code Optimization
• Main techniques of Optimization:-
Code Optimization
There are primarily 3 types of optimizations:-
(1) Local optimization - Apply to a basic block in isolation
(2) Global optimization - Apply across basic blocks
(3) Loop optimization – Apply on loops
Another significant optimization can be:-
(4) peep-hole optimization - Apply across boundaries
Code Optimization
• Optimization performed within a basic block.
• This is simplest form of optimizations
• No need to analyze the whole procedure body.
• Just analyze the basic blocks of the procedure.
• The local optimization techniques include:
– Constant Folding
– Constant Propagation
– Algebraic Simplification
– Operator Strength Reduction
– Dead Code Elimination
Local Code Optimization
A) Constant folding-
• As the name suggests, this technique involves folding
the constants by evaluating the expressions that
involves the operands having constant values at the
compile time.
• Ex: Circumference of circle = (22/7) x Diameter
• Replace (22/7) with 3.14 during compile time and save
the execution time.
Local Code Optimization
B) Constant Propagation-
• In this technique, if some variable has been assigned
some constant value, then it replaces that variable with
its constant value in the further program wherever it has
been used during compilation, provided that its value
does not get alter in between.
• Ex: pi = 3.14, radius = 10
• Area of circle = pi x radius x radius
• Substitutes constants value during compile time and
saves the execution time.
Local Code Optimization
C) Algebraic Simplification-
• Use algebraic properties to simplify expressions
• Some expressions can be simplified by replacing them
with an equivalent expression that is more efficient.
• Ex:
Code Optimization
D) Strength Reduction-
• As the name suggests, this technique involves
reducing the strength of the expressions by replacing
the expensive and costly operators with the simple and
cheaper ones
Code Optimization
E) Dead code elimination-
• Those code are eliminated which either never executes
or are not reachable or even if they get execute, their
output is never utilized.
Code Optimization
F) Common sub-expressions elimination:
• Eliminates the redundant expressions and avoids their
computation again and again.
Global Code Optimization
• Optimization across basic blocks within a procedure /function
• Could be restricted to a smaller scope, Example: a loop
• Data-flow analysis is done to perform optimization across basic
blocks
• Each basic block is a node in the flow graph of the program.
• These optimizations can be extended to an entire control - flow
graph
• Most of compiler implement global optimizations with well
founded theory and practical gains
Peephole Optimization
• Optimization technique that operates on the one or
few instructions at a time.
• Performs machine dependent improvements
• Peeps into a single or sequence of two to three
instructions (peephole) and replaces it by most
efficient alternative (shorter or faster) instructions.
• Peephole is a small moving window on the target
systems
Peephole Optimization
Characteristics of peep-hole optimizations:-
• Redundant-instruction (loads and stores)elimination
• Flow-of-control optimizations - - Elimination of
multiple jumps (i.e. goto statements)
• Elimination of unreachable code
• Algebraic simplifications
• Reducing operator strength
• Use of machine idioms
Loop Optimization
• Loop optimization plays an important role in
improving the performance of the source code by
reducing overheads associated with executing
loops.
• Loop Optimization can be done by removing:
–Loop invariant
–Induction variables
Loop Optimization
• Removal of Loop Invariant data:-
Loop Optimization
• Induction variables:-
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
THANK YOU !!!
Ad

More Related Content

What's hot (20)

COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
Vetukurivenkatashiva
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
Siva Sathya
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
Anul Chaudhary
 
Loop optimization
Loop optimizationLoop optimization
Loop optimization
Vivek Gandhi
 
unit testing and debugging
unit testing and debuggingunit testing and debugging
unit testing and debugging
KarthigaGunasekaran1
 
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil Kaushik
 
Run time storage
Run time storageRun time storage
Run time storage
Rasineni Madhan Mohan Naidu
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
Vairavel C
 
Chapter 15 software product metrics
Chapter 15 software product metricsChapter 15 software product metrics
Chapter 15 software product metrics
SHREEHARI WADAWADAGI
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
Uninformed search /Blind search in AI
Uninformed search /Blind search in AIUninformed search /Blind search in AI
Uninformed search /Blind search in AI
Kirti Verma
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
hermiraguilar
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
Jothi Lakshmi
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
Daniyal Mughal
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
Siva Sathya
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
Anul Chaudhary
 
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil Kaushik
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
Vairavel C
 
Chapter 15 software product metrics
Chapter 15 software product metricsChapter 15 software product metrics
Chapter 15 software product metrics
SHREEHARI WADAWADAGI
 
Uninformed search /Blind search in AI
Uninformed search /Blind search in AIUninformed search /Blind search in AI
Uninformed search /Blind search in AI
Kirti Verma
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
hermiraguilar
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
Daniyal Mughal
 

Similar to Code Optimization (20)

Fundamental principles of optimization and loop optimization techniques
Fundamental principles of optimization and loop optimization techniquesFundamental principles of optimization and loop optimization techniques
Fundamental principles of optimization and loop optimization techniques
ssharmilasharmila23
 
SPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization partSPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization part
NiramayKolalle
 
Downlaod Wise Registry Cleaner Pro Crack
Downlaod Wise Registry Cleaner Pro CrackDownlaod Wise Registry Cleaner Pro Crack
Downlaod Wise Registry Cleaner Pro Crack
tomcross837
 
Autodesk CFD Ultimate Crack Latest Version
Autodesk CFD Ultimate Crack Latest VersionAutodesk CFD Ultimate Crack Latest Version
Autodesk CFD Ultimate Crack Latest Version
losbeten
 
Download RarmaRadio Pro Crack Latest [2025]
Download RarmaRadio Pro Crack Latest [2025]Download RarmaRadio Pro Crack Latest [2025]
Download RarmaRadio Pro Crack Latest [2025]
wreeen464
 
Code_Optimization_Compiler_Design software .pptx
Code_Optimization_Compiler_Design software .pptxCode_Optimization_Compiler_Design software .pptx
Code_Optimization_Compiler_Design software .pptx
AmishaKumari97
 
NCH VideoPad Pro Cracked Version Download
NCH VideoPad Pro Cracked Version DownloadNCH VideoPad Pro Cracked Version Download
NCH VideoPad Pro Cracked Version Download
jasperjhin57
 
Download Artweaver Plus Cracked Version Free
Download Artweaver Plus Cracked Version FreeDownload Artweaver Plus Cracked Version Free
Download Artweaver Plus Cracked Version Free
adomalex314
 
PowerDirector Activated Full Tested Download
PowerDirector Activated Full Tested DownloadPowerDirector Activated Full Tested Download
PowerDirector Activated Full Tested Download
tomveren
 
Latest TreeSize Professional 9 Crack Download
Latest TreeSize Professional 9 Crack DownloadLatest TreeSize Professional 9 Crack Download
Latest TreeSize Professional 9 Crack Download
bentenkhan340
 
Peephole optimization techniques
Peephole optimization techniquesPeephole optimization techniques
Peephole optimization techniques
garishma bhatia
 
Embedded and Real Time Systems Unit II.pptx
Embedded and Real Time Systems Unit II.pptxEmbedded and Real Time Systems Unit II.pptx
Embedded and Real Time Systems Unit II.pptx
vanitha292520
 
Unit 1 Computer organization and Instructions
Unit 1 Computer organization and InstructionsUnit 1 Computer organization and Instructions
Unit 1 Computer organization and Instructions
Balaji Vignesh
 
Code optimization
Code optimizationCode optimization
Code optimization
Sameenafathima4
 
Cse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solutionCse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solution
Shobha Kumar
 
Parallel Computing - Lec 6
Parallel Computing - Lec 6Parallel Computing - Lec 6
Parallel Computing - Lec 6
Shah Zaib
 
L-2 (Computer Performance).ppt
L-2 (Computer Performance).pptL-2 (Computer Performance).ppt
L-2 (Computer Performance).ppt
ImranKhan997082
 
Basics of micro controllers for biginners
Basics of  micro controllers for biginnersBasics of  micro controllers for biginners
Basics of micro controllers for biginners
Gerwin Makanyanga
 
CSC 204 PASSES IN COMPILER CONSTURCTION.pptx
CSC 204 PASSES IN COMPILER CONSTURCTION.pptxCSC 204 PASSES IN COMPILER CONSTURCTION.pptx
CSC 204 PASSES IN COMPILER CONSTURCTION.pptx
ZulukhaniniTijani
 
BAXTER phase 1b
BAXTER phase 1bBAXTER phase 1b
BAXTER phase 1b
Franck MIKULECZ
 
Fundamental principles of optimization and loop optimization techniques
Fundamental principles of optimization and loop optimization techniquesFundamental principles of optimization and loop optimization techniques
Fundamental principles of optimization and loop optimization techniques
ssharmilasharmila23
 
SPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization partSPCC_Sem6_Chapter 6_Code Optimization part
SPCC_Sem6_Chapter 6_Code Optimization part
NiramayKolalle
 
Downlaod Wise Registry Cleaner Pro Crack
Downlaod Wise Registry Cleaner Pro CrackDownlaod Wise Registry Cleaner Pro Crack
Downlaod Wise Registry Cleaner Pro Crack
tomcross837
 
Autodesk CFD Ultimate Crack Latest Version
Autodesk CFD Ultimate Crack Latest VersionAutodesk CFD Ultimate Crack Latest Version
Autodesk CFD Ultimate Crack Latest Version
losbeten
 
Download RarmaRadio Pro Crack Latest [2025]
Download RarmaRadio Pro Crack Latest [2025]Download RarmaRadio Pro Crack Latest [2025]
Download RarmaRadio Pro Crack Latest [2025]
wreeen464
 
Code_Optimization_Compiler_Design software .pptx
Code_Optimization_Compiler_Design software .pptxCode_Optimization_Compiler_Design software .pptx
Code_Optimization_Compiler_Design software .pptx
AmishaKumari97
 
NCH VideoPad Pro Cracked Version Download
NCH VideoPad Pro Cracked Version DownloadNCH VideoPad Pro Cracked Version Download
NCH VideoPad Pro Cracked Version Download
jasperjhin57
 
Download Artweaver Plus Cracked Version Free
Download Artweaver Plus Cracked Version FreeDownload Artweaver Plus Cracked Version Free
Download Artweaver Plus Cracked Version Free
adomalex314
 
PowerDirector Activated Full Tested Download
PowerDirector Activated Full Tested DownloadPowerDirector Activated Full Tested Download
PowerDirector Activated Full Tested Download
tomveren
 
Latest TreeSize Professional 9 Crack Download
Latest TreeSize Professional 9 Crack DownloadLatest TreeSize Professional 9 Crack Download
Latest TreeSize Professional 9 Crack Download
bentenkhan340
 
Peephole optimization techniques
Peephole optimization techniquesPeephole optimization techniques
Peephole optimization techniques
garishma bhatia
 
Embedded and Real Time Systems Unit II.pptx
Embedded and Real Time Systems Unit II.pptxEmbedded and Real Time Systems Unit II.pptx
Embedded and Real Time Systems Unit II.pptx
vanitha292520
 
Unit 1 Computer organization and Instructions
Unit 1 Computer organization and InstructionsUnit 1 Computer organization and Instructions
Unit 1 Computer organization and Instructions
Balaji Vignesh
 
Cse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solutionCse viii-advanced-computer-architectures-06cs81-solution
Cse viii-advanced-computer-architectures-06cs81-solution
Shobha Kumar
 
Parallel Computing - Lec 6
Parallel Computing - Lec 6Parallel Computing - Lec 6
Parallel Computing - Lec 6
Shah Zaib
 
L-2 (Computer Performance).ppt
L-2 (Computer Performance).pptL-2 (Computer Performance).ppt
L-2 (Computer Performance).ppt
ImranKhan997082
 
Basics of micro controllers for biginners
Basics of  micro controllers for biginnersBasics of  micro controllers for biginners
Basics of micro controllers for biginners
Gerwin Makanyanga
 
CSC 204 PASSES IN COMPILER CONSTURCTION.pptx
CSC 204 PASSES IN COMPILER CONSTURCTION.pptxCSC 204 PASSES IN COMPILER CONSTURCTION.pptx
CSC 204 PASSES IN COMPILER CONSTURCTION.pptx
ZulukhaniniTijani
 
Ad

More from Akhil Kaushik (20)

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
Akhil Kaushik
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
Symbol Table
Symbol TableSymbol Table
Symbol Table
Akhil Kaushik
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
Akhil Kaushik
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
Akhil Kaushik
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
Akhil Kaushik
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
Akhil Kaushik
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
Akhil Kaushik
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
Akhil Kaushik
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
Akhil Kaushik
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
Akhil Kaushik
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in Python
Akhil Kaushik
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
Akhil Kaushik
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
Akhil Kaushik
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil Kaushik
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
Akhil Kaushik
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
Akhil Kaushik
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
Akhil Kaushik
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
Akhil Kaushik
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
Akhil Kaushik
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
Akhil Kaushik
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
Akhil Kaushik
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
Akhil Kaushik
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
Akhil Kaushik
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
Akhil Kaushik
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in Python
Akhil Kaushik
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
Akhil Kaushik
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil Kaushik
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
Akhil Kaushik
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
Akhil Kaushik
 
Ad

Recently uploaded (20)

Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 

Code Optimization

  • 1. Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani Code Optimization
  • 2. Optimization • In computing, optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. • Ex: a computer program may be optimized so that it executes more rapidly or is capable of operating with less memory storage or other resources, or draw less power. • The system may be a single computer program, a collection of computers or even an entire network such as the internet.
  • 3. Code Optimization • Optimization is a program transformation technique, which tries to improve the code that consume less resources (i.e. CPU, Memory) and deliver high speed. • In optimization, high-level general programming constructs are replaced by very efficient low-level programming codes. • Usually done at the end of the development stage since it reduces readability & adds code that is used to improve the performance.
  • 4. Code Optimization Optimized code’s features:- • Executes faster • Code size get reduced • Efficient memory usage • Yielding better performance • Reduces the time and space complexity
  • 5. Code Optimization Optimizations are classified into two categories: • Machine independent optimizations - improve target code without taking properties of target machine into consideration. • Machine dependent optimization - improve target code by checking properties of target machine.
  • 6. Code Optimization Criteria for Optimization:- • An optimization must preserve the meaning of a program: -Cannot change the output produced for any input. -Can not introduce an error. • Optimization should, on average, speed up programs. • Optimization should itself be fast and should not delay the overall compiling process.
  • 7. Code Optimization Optimization can occur at several levels: 1.Design level:- At the highest level, the design may be optimized to make best use of the available resources. – The implementation of this design will benefit from the use of suitable efficient algorithms and the implementation of these algorithms will benefit from writing good quality code. 2.Compile level:- Use of an optimizing compiler tends to ensure that the executable program is optimized at least as much as the compiler can predict
  • 8. Code Optimization Improvements can be made at various phases:- • Source Code: Algorithm's transformation can produce spectacular improvements • Intermediate Code: Compiler can improve loops, procedure calls and address calculations. -Typically only optimizing compilers include this phase • Target Code: Compilers can use registers efficiently
  • 9. Code Optimization • Main techniques of Optimization:-
  • 10. Code Optimization There are primarily 3 types of optimizations:- (1) Local optimization - Apply to a basic block in isolation (2) Global optimization - Apply across basic blocks (3) Loop optimization – Apply on loops Another significant optimization can be:- (4) peep-hole optimization - Apply across boundaries
  • 11. Code Optimization • Optimization performed within a basic block. • This is simplest form of optimizations • No need to analyze the whole procedure body. • Just analyze the basic blocks of the procedure. • The local optimization techniques include: – Constant Folding – Constant Propagation – Algebraic Simplification – Operator Strength Reduction – Dead Code Elimination
  • 12. Local Code Optimization A) Constant folding- • As the name suggests, this technique involves folding the constants by evaluating the expressions that involves the operands having constant values at the compile time. • Ex: Circumference of circle = (22/7) x Diameter • Replace (22/7) with 3.14 during compile time and save the execution time.
  • 13. Local Code Optimization B) Constant Propagation- • In this technique, if some variable has been assigned some constant value, then it replaces that variable with its constant value in the further program wherever it has been used during compilation, provided that its value does not get alter in between. • Ex: pi = 3.14, radius = 10 • Area of circle = pi x radius x radius • Substitutes constants value during compile time and saves the execution time.
  • 14. Local Code Optimization C) Algebraic Simplification- • Use algebraic properties to simplify expressions • Some expressions can be simplified by replacing them with an equivalent expression that is more efficient. • Ex:
  • 15. Code Optimization D) Strength Reduction- • As the name suggests, this technique involves reducing the strength of the expressions by replacing the expensive and costly operators with the simple and cheaper ones
  • 16. Code Optimization E) Dead code elimination- • Those code are eliminated which either never executes or are not reachable or even if they get execute, their output is never utilized.
  • 17. Code Optimization F) Common sub-expressions elimination: • Eliminates the redundant expressions and avoids their computation again and again.
  • 18. Global Code Optimization • Optimization across basic blocks within a procedure /function • Could be restricted to a smaller scope, Example: a loop • Data-flow analysis is done to perform optimization across basic blocks • Each basic block is a node in the flow graph of the program. • These optimizations can be extended to an entire control - flow graph • Most of compiler implement global optimizations with well founded theory and practical gains
  • 19. Peephole Optimization • Optimization technique that operates on the one or few instructions at a time. • Performs machine dependent improvements • Peeps into a single or sequence of two to three instructions (peephole) and replaces it by most efficient alternative (shorter or faster) instructions. • Peephole is a small moving window on the target systems
  • 20. Peephole Optimization Characteristics of peep-hole optimizations:- • Redundant-instruction (loads and stores)elimination • Flow-of-control optimizations - - Elimination of multiple jumps (i.e. goto statements) • Elimination of unreachable code • Algebraic simplifications • Reducing operator strength • Use of machine idioms
  • 21. Loop Optimization • Loop optimization plays an important role in improving the performance of the source code by reducing overheads associated with executing loops. • Loop Optimization can be done by removing: –Loop invariant –Induction variables
  • 22. Loop Optimization • Removal of Loop Invariant data:-