Re: lshift & rshift
On Sep 27, 3:15 am, "ie...@free .fr" <ie...@free.frw rote:
>
I can't, it was in past. But I'm sure. I asked a friend, and he
explain me that on some architecture (like the HP adding machine)
there wasn't a multiplication in the CPU, so the multiplication was a
software and it was better to use + than *. And it was not a lshift, I
swear it.
80% of the cost of software is maintenance.
So write code that is as clear and expressive as possible.
Do not try to out-think your compiler. Chances are very good that it
is better at optimization than you are.
If you *measure* a performance problem, then run a profiler against
the code to find out *where* the slow bits are. Typically, there will
be a couple places that need help. The way to fix these problem spots
is NOT by micro-optimizations like exchanging shifts for multiplies by
powers of two but by improving the algorithm. If (and only if) you
have measured to find out what is slow and you are unable to find or
produce a better algorithm, then it makes sense to do little tweaky
micro-optimizations or inline assembly. If you code that way from
scratch, then you are writing unmaintainable gobbledygook that won't
be fast anyway and will eventually cause great problems.
The first rule of optimization is: "Don't do it."
The second rule of optimization (for experts only) is: "Don't do it
yet."
On Sep 27, 3:15 am, "ie...@free .fr" <ie...@free.frw rote:
Can you post the snapshot of the internal of a*2 and a+a that you
got ?
got ?
I can't, it was in past. But I'm sure. I asked a friend, and he
explain me that on some architecture (like the HP adding machine)
there wasn't a multiplication in the CPU, so the multiplication was a
software and it was better to use + than *. And it was not a lshift, I
swear it.
So write code that is as clear and expressive as possible.
Do not try to out-think your compiler. Chances are very good that it
is better at optimization than you are.
If you *measure* a performance problem, then run a profiler against
the code to find out *where* the slow bits are. Typically, there will
be a couple places that need help. The way to fix these problem spots
is NOT by micro-optimizations like exchanging shifts for multiplies by
powers of two but by improving the algorithm. If (and only if) you
have measured to find out what is slow and you are unable to find or
produce a better algorithm, then it makes sense to do little tweaky
micro-optimizations or inline assembly. If you code that way from
scratch, then you are writing unmaintainable gobbledygook that won't
be fast anyway and will eventually cause great problems.
The first rule of optimization is: "Don't do it."
The second rule of optimization (for experts only) is: "Don't do it
yet."
Comment