优化问题 [英] Optimization question

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

问题描述

如果在程序的一小部分中,我可以使用

使用一个

valarray< int> var(size);

或a

int * var = new int [size];


我有两次在整个阵列中多次交流。

我想(通过探查器)已经知道这是我的

计划中的一个关键部分。

有不同的实现方式

a方式valarray版本可以跟上指针版本吗?


谢谢,

marc

If in a small part of the program, I could
use lets say a
valarray<int> var(size);
or a
int* var = new int[ size];

in both times I have to interate several times through the whole array.
I figured (via profiler) already out that this is a crucial part in my
program.

is there in different implementations
a way that the valarray version can keep up with the pointer version?

thanks,
marc

推荐答案



< m _ ********* @ hotmail.com>在消息中写道

新闻:11 ********************* @ o13g2000cwo.googlegro ups.com ...

|如果在程序的一小部分,我可以

|使用让我们说一个

|的valarray< INT> var(size);

|或者

| int * var = new int [size];

|

|在这两次我必须在整个阵列中进行多次交互。


也许如果你发布一个可以编译的非常小的测试用例,有人

可能能够提供一些帮助,否则,我们都在猜你的意思是什么(我认为是'迭代''?)

>
|我想(通过探查器)已经说明这是我的

|中的关键部分程序。

|

|有不同的实现

| valarray版本可以跟上指针版本的方式吗?


究竟要做什么?


干杯,

Chris Val

<m_*********@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
| If in a small part of the program, I could
| use lets say a
| valarray<int> var(size);
| or a
| int* var = new int[ size];
|
| in both times I have to interate several times through the whole array.

Maybe if you post a very small test case that can be compiled, someone
might be able to offer some assistance, otherwise, we''re all guessing
at what you mean by (what I presume is meant to be ''iterating''?)

| I figured (via profiler) already out that this is a crucial part in my
| program.
|
| is there in different implementations
| a way that the valarray version can keep up with the pointer version?

To do what exactly?

Cheers,
Chris Val


是我的意思是迭代。

实际上我使用[]运算符。

Keep up意味着保持速度,即速度快。


marc

Yes I meant iterating.
Actually I use the [] operator.
Keep up meant keep up speedwise, ie be as fast.

marc


m _ ********* @ hotmail.com 写道:
m_*********@hotmail.com wrote:
如果在程序的一小部分,我可以使用让我们说一个
valarray< int> var(size);
或者
int * var = new int [size];

两次我必须在整个数组中多次交互。
我想(通过分析器)已经知道这是我的
程序中的一个关键部分。

有不同的实现方式
valarray版本可以跟上的方式指针版本?
If in a small part of the program, I could
use lets say a
valarray<int> var(size);
or a
int* var = new int[ size];

in both times I have to interate several times through the whole array.
I figured (via profiler) already out that this is a crucial part in my
program.

is there in different implementations
a way that the valarray version can keep up with the pointer version?



你的意思是迭代向量比堆中的数组中的迭代要慢吗?你在堆数组中迭代的方式与你在向量中的方式相同吗?

你的系统中这个程序的输出是什么?

#include< iostream>

#include< vector>

#include< ctime>

int main()

{

使用命名空间std;


clock_t t1,t2,temp;


const unsigned SIZE = 10000000;


vector< int> vec(SIZE);


int * array = new int [SIZE];


for(temp = t1 = clock();! (t1-temp); t1 = clock());

;


for(vector< int> :: size_type i = 0; i< vec .size(); ++ i)

vec [i] = i;


t2 = clock();


cout<<"在vector'的情况下消耗的时间:<<< t2-t1<<" \\\
" ;;

for(temp = t1 = clock();!(t1-temp); t1 = clock());

;


for(unsigned i = 0; i< SIZE; ++ i)

array [i] = i;


t2 = clock();


cout<<<"数组'消耗的时间:"<< t2-t1<<" \ n" ;;


delete []阵列;

}


-

Ioannis Vranos

http://www23.brinkster.com/noicys


这篇关于优化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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