Is shifting bits faster than multiplying and dividing in Java? .NET? [closed]

Almost any environment worth its salt will optimize this away for you. And if it doesn’t, you’ve got bigger fish to fry. Seriously, do not waste one more second thinking about this. You will know when you have performance problems. And after you run a profiler, you will know what is causing it, and it should be fairly clear how to fix it.

You will never hear anyone say “my application was too slow, then I started randomly replacing x * 2 with x << 1 and everything was fixed!” Performance problems are generally solved by finding a way to do an order of magnitude less work, not by finding a way to do the same work 1% faster.

Leave a Comment