Not really.
Oh.. That wasn't a question, was it?
> Benchmarks over a million interations shows the funciton
> above as approximately ~55% of my total number. std::swap if memory
> serves is linear time so .. i'm wondering (laptop got fried last night
> so I'm unable to check) if a standard swap approach would eb more
> prudent
Why TF do you ask when it's possible only for you to answer - by trying
and measuring? Seriously, dude, use 'std::swap' and see.
The only two other comments: if your T has the same alignment
requirements as the CPU word, you could swap words instead of bytes and
get a bit of improvement that way. Another possible improvement is (a)
to pass by reference and avoid all the copying and (b) to use
reinterpret_cast (provided that it gives the correct answer on your
platform) and forgo internal copying to 'input'. You're in the
undefined behaviour land anyway with your use of unions.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Also, bitswapping is likely to not work on lots of types.
/Peter
Frankly it would be prudent for you tell me how you want me to work
with you. You see, I have no issues adapting and at this juncture do
me a favor and go F yourself. For years, I've watched your response on
this board and frankly I'm one who is tired of your nonsense. I made
it clear my laptop is fried and as such I'm using borrowed goods. Do
me a favor.... Stay clear of my F(ing) posts. Thank you.
> Not really.
His function doesn't do the same thing as std::swap. It looks
more like a value oriented version of std::reverse, i.e.
something like:
template< typename T, unsigned int size >
T reverse_bytes( T value )
{
std::reverse( reinterpret_cast< char* >( &value ),
reinterpret_cast< char* >( &value ) + size);
return value;
}
But the interface still looks a bit screwy: you have to
explicitly state each template argument. And it's not really
applicable except to arrays of char, since anything else will
result in undefined behavior, and a mess. And if T is an array
type, you can't pass or return it by value. And if it is a
container, you don't need the size argument; I could see some
argument for a function:
template< typename Container >
Container
reverse( Container c )
{
std::reverse( c.begin(), c.end() );
return c;
}
But using std::reverse_copy is likely to be faster most, if not
all of the time.
--
James Kanze
I don't. I don't know you: you have no name. I don't work with people
with no name. To me you're just a poster who asked a question. I don't
care to "work" with somebody who doesn't want to identify him-/herself.
> You see, I have no issues adapting and at this juncture do
> me a favor and go F yourself. For years, I've watched your response on
> this board and frankly I'm one who is tired of your nonsense.
For years you watched? I'm flattered... No, I guess I am not. I don't
care, really. Oh, did I offend you? I apologise. Only I don't know to
whom I just apologised. Because I have no idea who you are - you don't
sign your posts.
> I made
> it clear my laptop is fried and as such I'm using borrowed goods. Do
> me a favor.... Stay clear of my F(ing) posts. Thank you.
Sorry, no can do, unless you start top-posting or s-top posting (pun
intended). Why should I care that your laptop is fried? My potatoes
are fried, and it makes no difference to you, does it? You asked a
question that cannot be answered. Go find yourself something else to do
if you can't take my replies. Killfile me for all I care. Read
http://www.catb.org/~esr/faqs/smart-questions.html
My point is that it's useless to *ask* whether performance of one method
is better than some other method (unless they are clearly different only
from that particular point of view), and instead the performance has to
be *compared*, in real life, on a real system, once both methods are
correctly implemented. That's all. I don't want to pretend I know what
the OP meant about "prudence" of "standard swap approach", I've just
assumed the OP knows what they mean.
Does this explain my point?
"Game on"? <chuckle> Apparently you got nothing better to do. Oh well.
> [..]
> > [..]
I wasn't disagreeing with you in that regard. Just pointing out
that it makes no sense to compare his function with std::swap,
because they do radically different things. One step even
further back, so to speak.
And given the code and the discussion, I think it's probably
safe to say that the OP doesn't really know what they mean.
--
James Kanze