当前位置:网站首页>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 == 3First 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
边栏推荐
- I built another wheel: GrpcGateway
- Kubernetes 入门实战03 中级篇
- Bagging-Blending Multi-Model Fusion Short-Term Electricity Load Forecasting Based on Weighted Grey Correlation Projection
- 分布式限流 redission RRateLimiter 的使用及原理
- LeetCode_235_二叉搜索树的最近公共祖先
- Manage reading notes upward
- Microsoft SQL服务器被黑客入侵 带宽被窃取
- [ASP.NET Core] Dependency Injection for Option Classes
- 24. 两两交换链表中的节点
- idea的package没有空心
猜你喜欢

Leetcode 125. 验证回文串

High energy output!Tencent's internal MyCat middleware manual, both theoretical and practical

横向对比5种常用的注册中心,无论是用于面试还是技术选型,都非常有帮助

Verilog grammar basics HDL Bits training 07

IO/多路复用(select/poll/epoll)

VLAN实验

编译Hudi
![[ASP.NET Core] Dependency Injection for Option Classes](/img/3f/820b6e33897cf385c3206c02d741f8.png)
[ASP.NET Core] Dependency Injection for Option Classes

Current relay JL-8GB/11/AC220V

C# 枚举类型 于xaml 中区别
随机推荐
stm32 RTC闹钟唤醒低功耗模式
HJY-F931A/YJ三相电压继电器
横向对比5种常用的注册中心,无论是用于面试还是技术选型,都非常有帮助
TensorFlow自定义训练函数
电压继电器SRMUVS-100VAC-2H2D
柔性机械系统分布参数建模及其控制的研究与进展
Verilog语法基础HDL Bits训练 07
PanGu-Coder: 函数级的代码生成模型
Static LED display developed by single chip microcomputer
Difference between C# enumeration type and xaml
基于声信道分析的电缆隧道人员定位技术
STM32F1读取MLX90632非接触式红外温度传感器
Voltage relay h2d SRMUVS - 100 vac - 2
三个点语法和DOM观察者
pg_rewind 修复主备环境的时间线
contentDocument contentWindow, canvas, svg, iframe
2022-07-29 顾宇佳 学习笔记 异常处理
基于时延估计的扰动卡尔曼滤波器外力估计
【梦想起航】
win下怎么搭建php环境的方法教程