Sign In
Amol Ravande's Performance blog
Go Faster, Stronger and Higher
Translate This Page
Translate this page
Powered by
Microsoft® Translator
Options
Blog Home
Email Blog Author
Share this
RSS for posts
Atom
RSS for comments
Search
Advanced search options...
Search In:
Everything
Blogs
Forums
People
Groups
Places
Pages
Date range:
All Time
Last Year
Last 6 Months
Last 3 Months
Last Month
Last Week
Last Two Days
Tags
.NET
Deadlocks
Frontend
Memory
OutOfMemoryException
Sharepoint
SQL Performance
Startup performance
WAN
Web Test Plug-ins
Web Testing
WinDbg
Archive
Archives
May 2010
(1)
February 2009
(1)
December 2008
(1)
November 2008
(1)
July 2008
(1)
June 2008
(1)
September 2007
(2)
Need for speed:Loop performance
MSDN Blogs
>
Amol Ravande's Performance blog
>
Need for speed:Loop performance
Need for speed:Loop performance
amolravande
15 Sep 2007 9:22 AM
Comments
1
For those guys who havent heard about Loop unrolling here is a brief description about it. Loop unrolling is a way of optimizing the code by manipulating the iteration variable in the body of the loop thus reducing the number of checks each time the loop is iterated. Consider this following code.
for(int i=0;i<100;i++)
{
myfunc();
}
If you try to convert this code to assembly language you would see around half of the instructions were due to the loop overhead(i.e for conditional branches and jumps). Hence to optimize this, I would change it to
for(int i=0;i<100;)
{
myfunc();i++;
myfunc();i++;
myfunc();i++;
myfunc();i++;
}
This reduces the number of conditional branches and loops to 1/5th and hence reduces the overhead. Infact there are some compilers that perform loop unrolling. The Intel C/C++ compiler for linux gives you an option to specify at compile time the number of times the loop has to be unrolled. However the amount of loop unrolling and operations inside the loop body has to be carefully chosen. More unrolling may lead to increase in the register usage to store temporary variables.
You can try out timing the above piece of code to find out the difference using the technique specified in my earlier article
1 Comments
Blog - Comment List MSDN TechNet
Comments
Loading...
Leave a Comment
Name
Comment
Please add 1 and 3 and type the answer here:
Post