交换机中的数百个案例,优化? [英] Hundreds of cases in a switch, optimization?

查看:93
本文介绍了交换机中的数百个案例,优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我刚写了一个有200多个案例的函数。包含在开关

声明中。我想知道在这样的实施中是否存在性能问题。我需要以某种方式对其进行优化吗?


就生成的机器代码而言,交换机中的数百个案例如何与数百个不同别人的?编译器或处理器是否对此类结构化代码进行了优化?b $ b优化?我通常需要担心

的表现吗?


谢谢,

-

何世明

Hi,

I just wrote a function that has over 200 "cases" wrapped in a "switch"
statement. I''m wondering if there are performance issues in such
implementation. Do I need to optimize it some way?

In terms of generated machine code, how does hundreds of cases in a switch
differ from hundreds of if-elses? Do compilers or processors do any
optimization on such structured code? Do I need to worry about the
performance, usually?

Thanks,
--
He Shiming

推荐答案

if-elsses和switch之间应该没有区别

的性能。开关只是更容易阅读。也就是说,他们生产了相同的机器代码。

顺便说一句,我是从帕斯卡的角度说话,但它应该是

也适用到C.和你一样等待你回答。

there should be no difference between if-elsses and switches in terms
of performance. switches are only easier to read. ie, they produce
identical machine code.
by the way, i am talking from a pascal point of view but it should
also apply to C . Waiting like you for C guys to answer.


好的,谢谢你的信息。


-

何世明


" Alawna" <○****** @ gmail.com>。在消息中写道

news:11 ********************* @ g49g2000cwa.googlegro ups.com ...
Well, thanks for the information anyway.

--
He Shiming

"Alawna" <O.******@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
在性能方面,if-elsses和switch之间应该没有区别。开关只是更容易阅读。也就是说,他们生产相同的机器代码。顺便说一句,我是从帕斯卡的观点来谈,但它也应该适用于C.像你这样等待C家伙回答。
there should be no difference between if-elsses and switches in terms
of performance. switches are only easier to read. ie, they produce
identical machine code.
by the way, i am talking from a pascal point of view but it should
also apply to C . Waiting like you for C guys to answer.






何世明(NOSPAM)写道:


He Shiming (NOSPAM) wrote:


我刚写了一个有200多个案例的函数。包含在开关的声明中。我想知道这样的实施是否存在性能问题。我是否需要以某种方式对其进行优化?

就生成的机器代码而言,交换机中的数百个案例与数百个if-elses有何不同?编译器或处理器是否对此类结构化代码进行了任何优化?我通常需要担心性能吗?
Hi,

I just wrote a function that has over 200 "cases" wrapped in a "switch"
statement. I''m wondering if there are performance issues in such
implementation. Do I need to optimize it some way?

In terms of generated machine code, how does hundreds of cases in a switch
differ from hundreds of if-elses? Do compilers or processors do any
optimization on such structured code? Do I need to worry about the
performance, usually?




好​​吧,尝试使用if-else'的
看看你是否这么简单。


在很多情况下,我看到很多带有100'切换语句的代码

它不是_possible_来应用任何其他策略。但是,就性能而言,尽量保持在b / b
的情况下尽量保持你认为最有可能在切换块开始时出现的情况。

-

Imanpreet Singh Arora



Well, try to write these hundreds of switch statements using if-else''s
and see if you have it easy that way.

I have seen a lot of code with 100''s of switch statements in many cases
it is just not _possible_ to apply any other strategy. However, as far
as performance is concerned try to keep the cases that you feel are
most likely to occur at the beginning of the switch block.
--
Imanpreet Singh Arora


这篇关于交换机中的数百个案例,优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆