What is faster (x < 0) or (x == -1)?

That depends entirely on the ISA you’re compiling for, and the quality of your compiler’s optimizer. Don’t optimize prematurely: profile first to find your bottlenecks. That said, in x86, you’ll find that both are equally fast in most cases. In both cases, you’ll have a comparison (cmp) and a conditional jump (jCC) instructions. However, for … Read more

C# ‘is’ type check on struct – odd .NET 4.0 x86 optimization behavior

I worked up a similar example that fails the same way: using System; using System.Runtime.CompilerServices; public class Program { static void Main() { Console.Write(Verify(Test.Create())); Console.ReadLine(); } //[MethodImpl(MethodImplOptions.NoInlining)] static bool Verify(IDisposable item) { return item is Test; } struct Test : IDisposable { public void Dispose() { } public static Test Create() { return new Test(); … Read more

SSE2 option in Visual C++ (x64)

Seems to be all 64-bit processors has SSE2. Since compiler option always switched on by default no need to switch it on manually. From Wikipedia: SSE instructions: The original AMD64 architecture adopted Intel’s SSE and SSE2 as core instructions. SSE3 instructions were added in April 2005. SSE2 replaces the x87 instruction set’s IEEE 80-bit precision … Read more

Why is this loop changed?

In this situation changing while() to for() is not an optimization. There is simply no way to know from bytecode which one was used in a source code. There are many situations when: while(x) is the same as: for(;x;) Suppose we have a three similar java applications – one with while() statement, and two with … Read more

At what point are WebSockets less efficient than Polling?

The whole point of a websocket connection is that you don’t ever have to ping the app for changes. Instead, the client just connects once and then the server can just directly send the client changes whenever they are available. The client never has to ask. The server just sends data when it’s available. For … Read more