在性能方面哪个更好? “如果其他”或“评估” COBOL中的声明? [英] Which is better in terms of performance? "if else" or "Evaluate" statement in COBOL?

查看:94
本文介绍了在性能方面哪个更好? “如果其他”或“评估” COBOL中的声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在性能方面哪个更好?当我们需要检查的条件较少时,COBOL中的
if else evaluate 语句吗?

Which is better in terms of performance ? "if else" or "evaluate" statement in COBOL, when we have lesser conditons to check ?

推荐答案

似乎我们对OP持怀疑态度,所以下面是IBM Enterprise COBOL的示例:

It seems we have a doubter as an OP, so here's an example with IBM Enterprise COBOL:

    01  A PIC 9. 
    PROCEDURE DIVISION.
        ACCEPT A 
        IF A EQUAL TO 2
             CONTINUE 
        ELSE 
             CONTINUE 
        END-IF 
        EVALUATE A 
          WHEN 2 
             CONTINUE 
          WHEN OTHER 
             CONTINUE 
        END-EVALUATE 

这是生成的代码。您不需要了解IBM Mainframe Assembler,只需注意相同的地方即可。

And here is the code which is generated. You don't need to know IBM Mainframe Assembler, you just have to note that things are the same:

000008  IF                                                                    
   0002F8  D200 D0F8 8000          MVC   248(1,13),0(8)          TS2=0        
   0002FE  96F0 D0F8               OI    248(13),X'F0'           TS2=0        
   000302  95F2 D0F8               CLI   248(13),X'F2'           TS2=0        
   000306  4770 B126               BC    7,294(0,11)             GN=4(00030E) 
000009  CONTINUE                                                              
   00030A  47F0 B126               BC    15,294(0,11)            GN=5(00030E) 
   00030E                 GN=4     EQU   *                                    
000011  CONTINUE                                                              
   00030E                 GN=5     EQU   *                                    
000013  EVALUATE                                                              
000014  WHEN                                                                  
   00030E  D200 D0F8 8000          MVC   248(1,13),0(8)          TS2=0        
   000314  96F0 D0F8               OI    248(13),X'F0'           TS2=0        
   000318  95F2 D0F8               CLI   248(13),X'F2'           TS2=0        
   00031C  4770 B13C               BC    7,316(0,11)             GN=12(000324)
000015  CONTINUE                                                              
   000320  47F0 B13C               BC    15,316(0,11)            GN=11(000324)
   000324                 GN=12    EQU   *                                    
000016  WHEN                                                                  
000017  CONTINUE                                                              
   000324                 GN=11    EQU   *     

继续,它不生成指令,用于使IF和EVALUATE中的两条腿保持简单。

CONTINUE, which generates no instructions, is used to keep things simple for both "legs" in the IF and the EVALUATE.

没有理由相信任何非IBM编译器生成的代码对于这两个示例都是不同的。

There is no reason to believe that the code generated by any non-IBM compiler would differ for the two examples.

如果您不确定甚至不具备回答问题或发表评论的动力,那么当您召集精力提出问题时,不要期望过高。

If you don't even have the energy to respond to questions or make comments if you are unclear, then don't expect too much in the future when you do summon up the energy to ask a question.

返回原始...

如果您在COBOL程序中遇到性能问题,则很有可能无法关闭

If you have a performance problem in a COBOL program it is highly unlikely to be down to the use of IF or EVALUATE per se.

EVALUATE可以直接替代嵌套IF。

EVALUATE can be used as a direct replacement for a nested-IF.

如果找到一个旧的嵌套IF,它将看起来像这样:

If you find an old nested-IF it will look something like this:

IF A
    do something
ELSE
    IF B
        do something
    ELSE
        IF C
            do something
        ELSE
            IF D
                do something
            ELSE
                IF E
                    do something.

或者,像这样:

IF A
    do something
ELSE
IF B
    do something
ELSE
IF C
    do something
ELSE
IF D
    do something
ELSE
IF E
    do something.

由于句号/句号,您可以知道它是旧代码。

You can know it is old code, because of the full-stop/period.

嵌套IF的评估效果要好得多。

Nested-IFs in new code are much better as EVALUATE.

它们的用法之间应该没有真正的重叠,但是从性能的角度来看,如果有的话,这不是问题。

There should be no real overlap between their usage, but it is not problematic from a performance point of view if there is.

我不知道所有编译器,但是如果IF / ELSE生成相同的代码,我不会感到惊讶代码以简单的方式评估/何时/何时进行。

I don't know about all compilers, but I would not be surprised if an IF/ELSE generates identical code to a simple EVALUATE/WHEN/WHEN OTHER.

如果您有性能问题,请查看您的逻辑。

If you have a performance problem, look to your logic.

如果您只是想优化 COBOL程序以使其变得更好,那就不要管它了。弄清逻辑并易于理解。使程序可维护。

If you are thinking of just "optimising" a COBOL program to make it somehow better, forget about it. Get the logic straight and understandable. Make the program maintainable.

如果您想知道使程序运行更快(并且重点可能是一点),那么可以编写一些测试程序可以对不同类型的数字字段进行一些操作(使用显示,打包,DECMAL / COMP-3,二进制/ COMP /编译器提供的各种其他非浮点COMP选项)。

If you want to know about making your programs run a little faster (and the emphasis may be on a little) then write some test programs with some manipulations of numeric fields of different types (USAGE DISPLAY vs PACKED-DECIMAL/COMP-3 vs BINARY/COMP/various other non-floating-point COMP options provided by your compiler).

通过下标,计数,带小数位累加值,多个源计算来检查它们。然后,您将知道如何根据其用途定义字段,并且以后不必再考虑它。

Check them out with subscripting, counting, accumulating values with decimal places, computations with multiple sources. Then you'll know how to define your fields for the purpose that they have, and won't have to consider it afterwards.

如果您在哪里有站点标准,

If you have site standards where you are, use them.

不要只是编写COBOL程序,而是在工作后坐下来说现在要对其进行优化。这不是我们的工作。

Don't just write a COBOL programs and then sit down once they are working and say "now to optimise it". It's not what we do.

这篇关于在性能方面哪个更好? “如果其他”或“评估” COBOL中的声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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