Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 71251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:51:30+00:00 2026-05-10T19:51:30+00:00

I remember from C days that we were encouraged to use i > -1

  • 0

I remember from C days that we were encouraged to use

i > -1 

instead of

i >= 0 

because of performance.

Does this still apply in the C# .NET world? What are the performance implications of using one over the other with today’s compilers? i.e. Is the compiler clever enough to optimize these for you?

(As an aside try and type the question ‘use >= or >’ into the question field on Stack Overflow and see what happens.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:51:31+00:00Added an answer on May 10, 2026 at 7:51 pm

    No, there are no performance issues associated with comparison operators. And any good compiler would optimize something this trivial anyway.

    I’m not sure where you got the suggestion to use ‘i > -1’ rather than ‘i >= 0’. On the x86 architecture, it makes no difference which you use: either case takes exactly two instructions… one to compare and one to jump:

     ;; if (i > -1) {  cmp eax, -1  jle else then:  ... else:   ;; if (i >= 0) {  cmp eax, 0  jl else then:  ... else: 

    On most RISC architectures that I know, ‘i >= 0’ may actually be faster since there is usually a dedicated zero register, and ‘i > -1’ may require loading a constant. For example, MIPS only has a < instruction (no <=). Here is how the two constructs would be (naively!) expressed in MIPS assembly language:

     // if (i >= 0) {   (assuming i is in register %t0)   stl $t1, $0, $t0     // in C: t1 = (0 < t0)  beq $t1, $0, else    // jump if t1 == 0, that is if t0 >= 0  nop then:  ... else:  // if (i > -1) {    (assuming i is in register %t0)   addi $t2, $0, -1      // in C: t2 = -1  stl $t1, $t2, $t0      // in C: t1 = (t2 < t0) = (-1 < t0)  bne $t1, $0, else     // jump if t1 != 0, that is if t0 > -1  nop then:  ... else: 

    So in the naive, general case, it will actually be one instruction faster to do ‘i >= 0’ on MIPS. Of course, RISC code is so heavily optimizable that a compiler would likely change either of these instruction sequences almost beyond recognition 🙂

    So… the short answer is no no no, no difference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I distinctly remember from the early days of .NET that calling ToString on a
Currently, we use a giant configuration object that is serialized to/from XML. This has
I slightly remember from age old PHP days (years ago) that different functions wanted
I slightly remember from my age old Java days, that there was an RequestScope
From my age old php days (years ago) I slightly remember that I had
I remember from past having a utility that would allow to leak various system
I remember seeing somewhere that you could call python methods from inside C using
I am trying to create a thread and from what I remember this should
I vaguely remember some sort of setuptools wrapper that would generate .egg files from
I'm creating a new class that inherits from UIView. I remember that xcode 3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.