当前位置:网站首页>Loop nesting: why can large loops inside and small loops outside improve the running efficiency of programs
Loop nesting: why can large loops inside and small loops outside improve the running efficiency of programs
2022-06-29 07:29:00 【Just code】
A lot of people think , Loop nesting can be nested arbitrarily , Regardless of the number of cycles ;
But that's not the case ;
Programs are for computers , Eventually, it compiles and generates instructions that the computer can recognize ;
Today's computers in order to improve efficiency , The instruction execution mechanism will have branches of preprocessing instructions ;
In the case of loops, there are branch instructions , For example, a 100 The cycle of time , Except for the first and last prediction instruction errors , Other predicted instructions can predict the instructions in the loop ; It avoids the waste of time caused by fetching new instructions again when executing branch instructions .
For the two A and B For two cycles , When A Far greater than B When , Loops can be nested in two ways
Case one :A Outside ,B , , Every time you cycle ,B There will be two errors , Co cycle A Time ;A The loop itself also has two mispredictions , So the final instruction prediction error is A*2 +2 ;
The second case :B Outside ,A , , Each cycle will occur 2 Time prediction error , Co cycle B Time ;B There are also two errors in the loop itself , therefore , The resulting instruction prediction error is B*2 + 2;
because A Far greater than B, So finally, the first method predicts the number of errors A*2 +2>B*2 + 2; In the first case, fetching new instructions causes more time waste ;
therefore , When dealing with loop nesting ,“ The big cycle is inside , The small loop is out ” It's a good choice ;
边栏推荐
- Appium自动化测试基础 — ADB常用命令(三)
- Deploy Prometheus server service system management
- LeetCode_ Dynamic programming_ Medium_ 91. decoding method
- How to talk about salary correctly in software test interview?
- mmclassification安装与调试
- 详解Autosar Arxml中的CANFD报文及格式
- Digital IC Design - UART
- IMX6DL4.1.15支持EIM总线(下)——配置原理分析。
- 【翻译】Bink如何为英国一些最大的银行的数字忠诚度交易提供动力
- Solve the problem that NPM does not have permission
猜你喜欢

关联性——相关性分析
【翻译】簇拥而出。构建现代应用程序的设计方法

Explain canfd message and format in AUTOSAR arxml in detail

matlab simulink 电网扫频仿真和分析

部署Prometheus-server服务 system管理

Autosar SWC在Simulink中Parameter的使用
What tools do testers need to know

利用IPv6实现公网访问远程桌面

excel高级绘图技巧100讲(六)-甘特图在项目进度上的实战应用案例

The realization of changing pop-up background at any time
随机推荐
Genicam gentl standard ver1.5 (3) Chapter 4
Imx6dl4.1.15 supports EIM bus (Part 2) - configuration principle analysis.
uva10891
Markdown skill tree (2): paragraph and emphasis
MFC中利用CDockablePane实现悬浮窗
Solve the problem that NPM does not have permission
Shift/space studio "Aurora" project: building a villa in the sandbox metauniverse
WordPress adds article topping, password protection, and privacy Tags
Livedata source code appreciation - basic use
如何看待软件测试培训?你需要培训吗?
Who is the main body of the waiting insurance record? Record in the local network security, right?
Exploring the depth of objects in JVM series
uva10891
uva10859
Digital IC Design - UART
KingbbaseES V8R6集群维护案例之---集群之间数据迁移
服裝行業的CRM品牌供應商如何選型?
Deploy Prometheus server service system management
Redis of NoSQL database (II): introduction to redis configuration file
Redis in NoSQL database (4): redis publishing and subscription