Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand that if-else involves branch prediction

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to understand if-else involves branch prediction". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand if-else involves branch prediction".

First, take a look at a classic piece of code and count its execution time:

/ / test_predict.cc # include # include # include int main () {const unsigned ARRAY_SIZE = 50000; int data [array _ SIZE]; const unsigned DATA_STRIDE = 256; for (unsigned c = 0; c

< ARRAY_SIZE; ++c) data[c] = std::rand() % DATA_STRIDE; std::sort(data, data + ARRAY_SIZE); { // 测试部分 clock_t start = clock(); long long sum = 0; for (unsigned i = 0; i < 100000; ++i) { for (unsigned c = 0; c < ARRAY_SIZE; ++c) { if (data[c] >

Sum + = data [c];}} double elapsedTime = static_cast (clock ()-start) / CLOCKS_PER_SEC; std::cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report