当前位置:网站首页>The method of judging the same variable without the if branch
The method of judging the same variable without the if branch
2022-07-30 11:47:00 【hibernating knives】
For the problem of using the same variable for multiple conditions, taking equal judgment
if a == 1else if a == 2else if a == 3
First of all, to optimize the look and feel, it is better to convert magic numbers such as 1, 2, 3
into enumeration types and use meaningful names to standardize them, rather than using magic numbers directlymany.
Secondly, to optimize the performance, change the multi-if branch to the hash method, for example, use a hashmap key to store all 1, 2, 3
, change 1,2, 3 The functions executed by
, write three functions respectively, store the objects of these three functions in the value of the hashmap, and establish a mapping.
Many software projects like to use this design method,
but this method also has limitations in many cases, maybe the final performance optimization is just self-deception,
discrete function executionAt the same time, it also causes the distribution of functions in memory to be more discrete. In the case of a large amount of functions, it may lead to CPU Cache Miss, which needs to be read into the paging from the memory again, resulting in entering the operating system kernel state
边栏推荐
- MySQL——数据库基础
- TensorFlow自定义训练函数
- 流水线上的农民:我在工厂种蔬菜
- Database transactions, JDBC operations and data types
- C language - bitwise operations
- Microsoft SQL server hacked, bandwidth stolen
- PL5920 SOT-23-6 21V、2A、600KHz同步降压DC/DC转换器
- RY-D1/1电压继电器
- Based on the analysis of the acoustic channel cable tunnel positioning technology
- Vim plugin GrepIt
猜你喜欢
Still using Swagger?I recommend this interface management artifact with zero code intrusion
contentDocument contentWindow, canvas, svg, iframe
反转链表-递归反转法
云原生应用的概念和云原生应用的 15 个特征
Current relay JL-8GB/11/AC220V
Explain the problem of change exchange in simple terms - the shell of the backpack problem
LeetCode_236_Last Common Ancestor of a Binary Tree
IO/多路复用(select/poll/epoll)
周鸿祎:微软抄袭了360安全模式 所以成为美国最大的安全公司
Verilog语法基础HDL Bits训练 08
随机推荐
2022-07-29 Gu Yujia Study Notes Exception Handling
ansible学习笔记01
win下怎么搭建php环境的方法教程
eric6教程(电脑的配置基本知识)
ABP学习资源整理
oracle export dmp file type as "crash dump file"
208. 实现 Trie (前缀树)
单片机工程师笔试题目归纳汇总
柔性机械系统分布参数建模及其控制的研究与进展
编译Hudi
定制.NET 6.0的依赖注入
Verilog grammar basics HDL Bits training 08
Is it too late to apply for PMP now to take the September exam?Share agile full-true mock questions
Hu-cang integrated e-commerce project (1): project background and structure introduction
spin lock和mutex使用场景的差异
The package of idea is not hollow
Manage reading notes upward
久经沙场的程序员居然也被某鱼的假程序员骗了,程序员之间的信任应该是最高的,他一个人毁了这种信任感
unity3d C#语言基础(继承)
Beyond Stream Processing!The 4th real-time computing Flink challenge is launched, and 490,000 prizes are waiting for you!