| Author |
Message |
Isaac Gerg
Guest
|
Posted:
Mon Dec 13, 2004 9:24 pm Post subject:
Vectors vs Arrays? |
|
|
I have an algorithm.
Will it perform faster if it utilizes vectors or arrays w/ pointers?
Why? |
|
| Back to top |
|
 |
Jerry Avins
Guest
|
Posted:
Mon Dec 13, 2004 10:25 pm Post subject:
Re: Vectors vs Arrays? |
|
|
Isaac Gerg wrote:
| Quote: | I have an algorithm.
Will it perform faster if it utilizes vectors or arrays w/ pointers?
Why?
|
It depends on the algorithm. It depends on the processor architecture.
It depends on the available software. For a text editor, it probably
doesn't matter.
Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ |
|
| Back to top |
|
 |
Isaac Gerg
Guest
|
Posted:
Mon Dec 13, 2004 11:26 pm Post subject:
Re: Vectors vs Arrays? |
|
|
Say I have an algorithm to perform which sequentially access data in an
array. Is it better to use the vector type or the array type with a
pointer. I argue that the array type with a pointer is fastest.
Thoughts?
Jerry Avins wrote:
| Quote: | Isaac Gerg wrote:
I have an algorithm.
Will it perform faster if it utilizes vectors or arrays w/ pointers?
Why?
It depends on the algorithm. It depends on the processor architecture.
It depends on the available software. For a text editor, it probably
doesn't matter.
Jerry |
|
|
| Back to top |
|
 |
Jerry Avins
Guest
|
Posted:
Mon Dec 13, 2004 11:32 pm Post subject:
Re: Vectors vs Arrays? |
|
|
Isaac Gerg wrote:
| Quote: | Say I have an algorithm to perform which sequentially access data in an
array. Is it better to use the vector type or the array type with a
pointer. I argue that the array type with a pointer is fastest.
Thoughts?
Jerry Avins wrote:
Isaac Gerg wrote:
I have an algorithm.
Will it perform faster if it utilizes vectors or arrays w/ pointers?
Why?
It depends on the algorithm. It depends on the processor architecture.
It depends on the available software. For a text editor, it probably
doesn't matter.
Jerry
|
Did you intend to address this to me at home? That's not appreciated,
and deprives you of the responses of those who may know more than I do.
Which is faster depends on how good your compiler is at optimizing and
on the architecture of your processor. A really good compiler might
generate exactly the same machine instructions however you write the
code. For the best speed, write in assembler, and address your elements
from an auto-incremented register. Study the operation of the MAC
instruction in almost any DSP. Typically, a MAC fetches two operands --
one of them from a circular buffer -- while adding the the product of
the previous fetches to an accumulator and incrementing the pointers. It
does it all in a single execution cycle. Moreover, zero-overhead looping
can be applied, so there is no need to check a counter inside a loop.
Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ |
|
| Back to top |
|
 |
Isaac Gerg
Guest
|
Posted:
Mon Dec 13, 2004 11:40 pm Post subject:
Re: Vectors vs Arrays? |
|
|
Apologies on accidentally emailing you at home.
Thank you for your reply.
I will elaborate a bit more. I am doing DSP'ing on Intel Itanium 64bit
machines. I have several function which loop sequentially through an
array. I am wondering if putting these arrays in vector notation will
aid the compilier during optimization. I am using Intel 8.1 C Compiler
with HP-MLIB.
Isaac |
|
| Back to top |
|
 |
Jon Harris
Guest
|
Posted:
Mon Dec 13, 2004 11:49 pm Post subject:
Re: Vectors vs Arrays? |
|
|
In Matlab, yes! :-)
In seriousness, there are too many unknowns to intelligently answer this
question.
"Isaac Gerg" <isaac.gergNOSPAM@adelphia.net> wrote in message
news:emjvd.1$az3.0@dfw-service2.ext.ray.com...
| Quote: | I have an algorithm.
Will it perform faster if it utilizes vectors or arrays w/ pointers?
Why? |
|
|
| Back to top |
|
 |
Jerry Avins
Guest
|
Posted:
Tue Dec 14, 2004 12:33 am Post subject:
Re: Vectors vs Arrays? |
|
|
Isaac Gerg wrote:
| Quote: | Apologies on accidentally emailing you at home.
Thank you for your reply.
I will elaborate a bit more. I am doing DSP'ing on Intel Itanium 64bit
machines. I have several function which loop sequentially through an
array. I am wondering if putting these arrays in vector notation will
aid the compilier during optimization. I am using Intel 8.1 C Compiler
with HP-MLIB.
Isaac
|
Try it both ways and see. The first rule of both exploring and trouble
shooting is "Poke it and watch how it wiggles."
Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ |
|
| Back to top |
|
 |
David Kirkland
Guest
|
Posted:
Tue Dec 14, 2004 6:46 pm Post subject:
Re: Vectors vs Arrays? |
|
|
Isaac Gerg wrote:
| Quote: | Apologies on accidentally emailing you at home.
Thank you for your reply.
I will elaborate a bit more. I am doing DSP'ing on Intel Itanium 64bit
machines. I have several function which loop sequentially through an
array. I am wondering if putting these arrays in vector notation will
aid the compilier during optimization. I am using Intel 8.1 C Compiler
with HP-MLIB.
Isaac
|
Do you mean C++ vectors and arrays? You say you're using a 'C' compiler
though?
If you mean C++ and are refering to the STL then your question is really
better asked at comp.lang.c++ or the moderated version of that group.
I would read through the STL docuemntation - they put limits like O(n)
or O(n^2) on the access, read, write time for the various objects. So it
will depend heavily on what you're doing (searching, resizing, or random
access). You may also want to look at val_array - this object allows you
to take sin/cos of the entire array.
You'll need to look at the entire range of functionality you intend to
use before determining the correct class - and there are usually some
trade offs. For instance some classes support slicing the data in
various ways.
Also note - unless you have the optimizing compiler then the STL is
deadly slow, and you'd be much better off using standard 'C' type arrays.
Cheers,
David |
|
| Back to top |
|
 |
|
|
|
|