# How many cycles do these operations take

[codebox]//First version

if(NP == 0) EP = 0;

else EP = inputArray[barNumber + INPUT_O];

//Second version

EP = inputArray[barNumber + INPUT_O] * abs(NP);[/codebox]

The above code statements produce the same result.

The question is which is faster.

Worst case scenario for the first, must be, half a warp goes if, half a warp goes else, taking 100% more cycles, but how many cycles is an if to begin with?

The later always performs an addition and a multiplication, that’s 8 cycles. How can I find out how many cycles the abs takes?

The time taken by the memory read and then write can differ quite a lot, I know that, I’m trying to understand it now.

You might find it illuminating to compile these two cases to the PTX level (nvcc --ptx) and compare the result from the compiler. Small divergence, like the first case, is probably much quicker (and easier to understand) than any mathematical trick to avoid the branch.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9034729,"math_prob":0.93308437,"size":649,"snap":"2022-27-2022-33","text_gpt3_token_len":168,"char_repetition_ratio":0.0883721,"word_repetition_ratio":0.0,"special_character_ratio":0.25885978,"punctuation_ratio":0.12686567,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9832712,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-02T18:29:22Z\",\"WARC-Record-ID\":\"<urn:uuid:56251950-9b15-4151-aa6a-07f1a6a81fe2>\",\"Content-Length\":\"24353\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9e665e86-865d-4abe-b5c3-f86c082d7eae>\",\"WARC-Concurrent-To\":\"<urn:uuid:a5415496-349b-40bf-9db6-6a5b51af4994>\",\"WARC-IP-Address\":\"184.105.176.47\",\"WARC-Target-URI\":\"https://forums.developer.nvidia.com/t/how-many-cycles-do-these-operations-take/7860\",\"WARC-Payload-Digest\":\"sha1:56CRLNL2U52UIO4DKNWADZM3GN3CILVP\",\"WARC-Block-Digest\":\"sha1:N7XGQYDUH3GG5ZJZJTGYFV4A24FLFPG3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104189587.61_warc_CC-MAIN-20220702162147-20220702192147-00691.warc.gz\"}"}