使用本地和全局数组进行优化 [英] Optimization with local vs. global arrays

查看:62
本文介绍了使用本地和全局数组进行优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将
全局声明某些数组而不是本地数据,则以下代码的执行速度会大大加快。那是


FOO a [10],b [10],c [10];


void bar(){

...

}




$ b $运行得快得多(高达33%) b void bar(){

FOO a [10],b [10],c [10];

...

}


...部分正在进行相当多的工作。

这是在Linux Itanium II系统上,使用英特尔C ++编译启用了过程间优化的
编译器(V9.1),以及带有-O3优化的

GNU CV 3.3.5编译器。 (对于英特尔编译器,性能变化更为显着。)我尝试使用


声明本地

FOO阵列静态静态FOO a [10],b [10],c [10];


有助于GNU编译器,但实际上更糟糕的是英特尔

编译器。我也尝试了


FOO d [30];

FOO * a = d,* b = d + 10,* c = d + 20; <带有本地d数组的
但是没有效果。


这只是一个编译器问题,还是我错过了什么?显然,我想避免使用外部数组,但是由英特尔

编译器编译的代码到目前为止执行速度最快。我希望得到

等效性能,而不是全局数组。

The execution speed of the following code is dramatically faster if I
declare some arrays globally rather than locally. That is

FOO a[10], b[10], c[10];

void bar() {
...
}

runs much faster (up to 33%) than

void bar() {
FOO a[10], b[10], c[10];
...
}

There is considerable work being performed in the ... section.
This is on a Linux Itanium II system, compiled both with the Intel C++
compiler (V9.1) with interprocedural optimization enabled, and with the
GNU C V 3.3.5 compiler with -O3 optimization. (The performance change is
more dramatic with the Intel Compiler.) I tried declaring the local
FOO arrays static with

static FOO a[10], b[10], c[10];

which helped with the GNU compiler but was actually worse with the Intel
compiler. I also tried

FOO d[30];
FOO *a = d, *b = d+10, *c = d+20;

with a local d array, but that had no effect.

Is this just a compiler issue, or am I missing something? I want to avoid
the external arrays, obviously, but that code compiled by the Intel
compiler gives the fastest execution speed by far. I''d like to get the
equivalent performance with something less dangerous than global arrays.

推荐答案


Jim West < eg *********** @ yahoo.comwrote in message

news:9F ******************* @ newsfe20.lga ...

"Jim West" <eg***********@yahoo.comwrote in message
news:9F*******************@newsfe20.lga...

如果我将
全局声明某些数组而不是本地数据,则以下代码的执行速度会大大加快。那是


FOO a [10],b [10],c [10];


void bar(){

...

}




$ b $运行得快得多(高达33%) b void bar(){

FOO a [10],b [10],c [10];

...

}


...部分正在进行相当多的工作。

这是在Linux Itanium II系统上,使用英特尔C ++编译启用了过程间优化的
编译器(V9.1),以及带有-O3优化的

GNU CV 3.3.5编译器。 (对于英特尔编译器,性能变化更为显着。)我尝试使用


声明本地

FOO阵列静态静态FOO a [10],b [10],c [10];


有助于GNU编译器,但实际上更糟糕的是英特尔

编译器。我也尝试了


FOO d [30];

FOO * a = d,* b = d + 10,* c = d + 20; <带有本地d数组的
但是没有效果。


这只是一个编译器问题,还是我错过了什么?显然,我想避免使用外部数组,但是由英特尔

编译器编译的代码到目前为止执行速度最快。我想用比全局数组更危险的东西获得

等效性能。
The execution speed of the following code is dramatically faster if I
declare some arrays globally rather than locally. That is

FOO a[10], b[10], c[10];

void bar() {
...
}

runs much faster (up to 33%) than

void bar() {
FOO a[10], b[10], c[10];
...
}

There is considerable work being performed in the ... section.
This is on a Linux Itanium II system, compiled both with the Intel C++
compiler (V9.1) with interprocedural optimization enabled, and with the
GNU C V 3.3.5 compiler with -O3 optimization. (The performance change is
more dramatic with the Intel Compiler.) I tried declaring the local
FOO arrays static with

static FOO a[10], b[10], c[10];

which helped with the GNU compiler but was actually worse with the Intel
compiler. I also tried

FOO d[30];
FOO *a = d, *b = d+10, *c = d+20;

with a local d array, but that had no effect.

Is this just a compiler issue, or am I missing something? I want to avoid
the external arrays, obviously, but that code compiled by the Intel
compiler gives the fastest execution speed by far. I''d like to get the
equivalent performance with something less dangerous than global arrays.



更快的处理器?

Faster processor?


Jim West写道:
Jim West wrote:

如果我将
全局声明某些数组而不是本地数据,则以下代码的执行速度会大大提高。那是


FOO a [10],b [10],c [10];


void bar(){

...

}




$ b $运行得快得多(高达33%) b void bar(){

FOO a [10],b [10],c [10];

...

}


...部分正在进行相当多的工作。

这是在Linux Itanium II系统上,使用英特尔C ++编译启用了过程间优化的
编译器(V9.1),以及带有-O3优化的

GNU CV 3.3.5编译器。 (对于英特尔编译器,性能变化更为显着。)我尝试使用


声明本地

FOO阵列静态静态FOO a [10],b [10],c [10];


有助于GNU编译器,但实际上更糟糕的是英特尔

编译器。我也尝试了


FOO d [30];

FOO * a = d,* b = d + 10,* c = d + 20; <带有本地d数组的
但是没有效果。


这只是一个编译器问题,还是我错过了什么?显然,我想避免使用外部数组,但是由英特尔

编译器编译的代码到目前为止执行速度最快。我想用比全局数组更危险的东西获得

等效性能。
The execution speed of the following code is dramatically faster if I
declare some arrays globally rather than locally. That is

FOO a[10], b[10], c[10];

void bar() {
...
}

runs much faster (up to 33%) than

void bar() {
FOO a[10], b[10], c[10];
...
}

There is considerable work being performed in the ... section.
This is on a Linux Itanium II system, compiled both with the Intel C++
compiler (V9.1) with interprocedural optimization enabled, and with the
GNU C V 3.3.5 compiler with -O3 optimization. (The performance change is
more dramatic with the Intel Compiler.) I tried declaring the local
FOO arrays static with

static FOO a[10], b[10], c[10];

which helped with the GNU compiler but was actually worse with the Intel
compiler. I also tried

FOO d[30];
FOO *a = d, *b = d+10, *c = d+20;

with a local d array, but that had no effect.

Is this just a compiler issue, or am I missing something? I want to avoid
the external arrays, obviously, but that code compiled by the Intel
compiler gives the fastest execution speed by far. I''d like to get the
equivalent performance with something less dangerous than global arrays.



每次调用bar时,本地数组(可能是
被推入堆栈)并不特别令人惊讶慢于全局数组的b / b
。如果你想要一些更安全的东西您可以尝试将数组移动到命名空间。


Mark

It''s not especially surprising that the local arrays, which may be
pushed on the stack with each invocation of bar, would be slower than
the global arrays. If you want something "safer" you could try moving
the arrays to a namespace.

Mark


2007-04 -12,GeekBoy< ne*@nerdy.com写道:
On 2007-04-12, GeekBoy <ne*@nerdy.comwrote:

>

处理器速度更快?
>
Faster processor?



不,所有都在同一个系统,操作系统等上运行。它使用

编译英特尔编译器使用


icc -O3 -ip -c foo.cc


和使用GNU编译器


g ++ -O3 -c foo.cc

No, all are run on the same system, OS etc. It is compiled with
the Intel compiler using

icc -O3 -ip -c foo.cc

and with the GNU compiler using

g++ -O3 -c foo.cc


这篇关于使用本地和全局数组进行优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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