473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Optimization question

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

Jul 23 '05 #1
3 1612

<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
Jul 23 '05 #2
Yes I meant iterating.
Actually I use the [] operator.
Keep up meant keep up speedwise, ie be as fast.

marc

Jul 23 '05 #3
m_*********@hotmail.com wrote:
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?

Do you mean that iterating vector is slower than iterating in the array in the heap? Do
you iterate in the heap array with the same way that you do in vector?
What are the outputs of this program in your system?
#include <iostream>
#include <vector>
#include <ctime>
int main()
{
using namespace 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<<"Time consumed in vector's case: "<<t2-t1<<"\n";
for(temp=t1=clock(); !(t1-temp); t1=clock());
;

for(unsigned i=0; i<SIZE; ++i)
array[i]= i;

t2=clock();

cout<<"Time consumed in array's case: "<<t2-t1<<"\n";

delete[] array;
}

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nick L. | last post by:
All, This is a general question regarding how, and if, compiler optimization techniques affect the general concept of being able to update a component of an application without requiring a...
20
by: Jakob Bieling | last post by:
Hi! I am using VC++ 7.1 and have a question about return value optimization. Consider the following code: #include <list> #include <string> struct test {
5
by: AC Slater | last post by:
Whats the simplest way to change a single stored procedures query optimization level? In UDB8 that is. /F
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
93
by: roman ziak | last post by:
I just read couple articles on this group and it keeps amazing me how the portability is used as strong argument for language cleanliness. In my opinion, porting the program (so you just take the...
22
by: NigelW | last post by:
This is really a question for the development team. Are there plans to improve the optimization of C# to MSIL? I ask this, as inspection with ILDASM of the MSIL code shows that, even with the...
5
by: wkaras | last post by:
I've compiled this code: const int x0 = 10; const int x1 = 20; const int x2 = 30; int x = { x2, x0, x1 }; struct Y {
0
by: Adam Sandler | last post by:
Hello, Using VWD 2005 here... I've noticed I've got .NET services on my system here: the .NET Runtime Optimization service and ASP.NET State service. I've noticed when the ASP.NET State service...
18
by: terminator(jam) | last post by:
consider: struct memory_pig{//a really large type: memory_pig(){ std::cout<<"mem pig default\n"; //etc... }; memory_pig(memory_pig const&){
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.