Re: Fastest way to read numbers in ascending order from array of integ
- From: Jerry Coffin <jcoffin@xxxxxxxxx>
- Date: Mon, 7 Aug 2006 16:38:43 -0600
In article <6E363210-0FD3-45A3-A2DC-CE30F8BA18B2@xxxxxxxxxxxxx>,
Srini@xxxxxxxxxxxxxxxxxxxxxxxxx says...
[ ... ]
Wondering what would be the fastest way to find the numbers(samllest one
first, the next big one next, so on until all the numbers in the array are
read) in their ascending order.
The obvious way would be to sort the array (e.g. std::sort). Less
obvious would be to use a priority_queue. At a guess, std::sort is
probably closer to what you want.
Once all the numbers are read, the array will be written with another set of
numbers. This reading(in ascending order) and writing continues couple of
thousand times a second.
Okay. Is this really a single stream of data, or is there a good reason
each of these has to be separate from the others? If you're trying to
implement something like a merge sort, you're generally better off not
keeping the initial runs separate from each other.
Also the procedure should not only be fast but also efficient in CPU cycles.
Does any one have any ideas? Should I go to assembly code here?
The first real question is how much data you're really going to be
working with -- "three or more numbers" is pretty open, to put it
mildly. If you're really looking at less than (say) 100 each time,
chances it the sort you use hardly matters at all -- you'll be able to
sort faster than you can read/write the data. If you're looking at a
million items each time, keeping up may take a lot more work.
--
Later,
Jerry.
The universe is a figment of its own imagination.
.
- Prev by Date: Re: do allocators have to be stateless?
- Next by Date: Re: Fastest way to read numbers in ascending order from array of i
- Previous by thread: do allocators have to be stateless?
- Next by thread: Re: Fastest way to read numbers in ascending order from array of i
- Index(es):
Relevant Pages
|