c# - What is more efficient, bitwise or equality checking? -


i writing few conditional variables, , figured easier set value result of equality between 2 boolean values.

what faster/more efficient processing side, marginal?

bool output = true&true; 

or

bool output = true&&true; 

i expect latter single equality check rather computing entire byte


thanks , apologies on vagueness previously. robbas answer, if code similar to:

bool input1 = generatefirstvalue(); bool input2 = generatesecondvalue(); bool output = input1 && input2; 

a clear improvement drop first 2 lines declaration mean when value false more efficient on bitwise checks, or presetting values. when logic has intensive methods.

    bool output = generatefirstvalue() && generatesecondvalue(); 

and doing that, sort checks least demanding first.

in hypothetical example doubt matters evaluating true crazy fast (if not compiled away completely)

take example however:

bool output = verylongfunction() & otherverylongfunction(); 

vs

bool output = verylongfunction() && otherverylongfunction(); 

in case double && short circuits expression if first evaluates false , faster using 1 &.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -