loop unrolling in C++
2014-02-28 21:46
148 查看
In the high-level view of a language, you're not going to see the optimization. The speed enhancement comes from what the compiler does with what you have.
In the first case, it's something like:
In the second it's something like:
You can see in the latter case, the overhead of testing and jumping is only 1 instruction per 3. In the first it's 1 instruction per 1; so it happens a lot more often.
In the first case, it's something like:
LOCATION_FLAG; DO_SOMETHING; TEST FOR LOOP COMPLETION;//Jumps to LOCATION_FLAG if false
In the second it's something like:
LOCATION_FLAG; DO_SOMETHING; DO_SOMETHING; DO_SOMETHING; TEST FOR LOOP COMPLETION;//Jumps to LOCATION_FLAG if false
You can see in the latter case, the overhead of testing and jumping is only 1 instruction per 3. In the first it's 1 instruction per 1; so it happens a lot more often.
相关文章推荐
- C++ STL erase in for loop
- Dev-c++ [Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
- 实现自己的http server - loop_in_codes - C++博客
- kingofark's Ineffective C/C++:自白1:返回值的运用
- Data Structure Linked List: Detect and Remove Loop in a Linked List
- Difference Between Vector and Deque in C++
- kingofark's Ineffective C/C++:低手自序
- Thinking in C++ learning(2)-----Data Abstract
- All C++ In-Depth Series Books
- Introduction to C++ Programming in UE4
- C++ 使用oci访问数据库出现“Column: 2<DOUBLE>, datatype in operator <</>>: CHAR”
- How to separate the implementation and definition for template function in c++
- forward declarations in c++
- 继 <ZMQ的学习和研究> 学习代码 Request-reply client in C++
- 【ThinkingInC++】51、最好还是把定义放到外面,用inline来实现内联,而不是在类里面定义默认为内联
- Parsing C++ in Python with Clang
- leetcode 434. Number of Segments in a String 按照空格分割字符串 + C++的stringstream的一个很好应用示范
- Using Kinect SDK in C++ project
- Embedding Python in C/C++: Part I