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

  • Home
  • SEARCH
  • 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 983063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:47:45+00:00 2026-05-16T04:47:45+00:00

wraparound_counter & operator ++() { m_count = (m_count + 1) % upper_limit; /*if (upper

  • 0
wraparound_counter & operator ++() {
    m_count = (m_count + 1) % upper_limit;
    /*if (upper == m_count)
        m_count = lower;
    ++m_count;*/
    return *this;
}

It is my understanding that on some systems using the remainder operator trick will be faster, but on others the conditional will be faster. Is there any way to figure out which will be faster at compile-time (or run-time)?

  • 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. Editorial Team
    Editorial Team
    2026-05-16T04:47:46+00:00Added an answer on May 16, 2026 at 4:47 am

    For most platforms, you can assume that the conditional will be faster. This is because most modern architecture where branch mispredictions are expensive have some form of conditional move instruction, which the compiler will utilize to perform the requested check & assignment. For example, my gcc translates this:

    n++; if (n==1234) n=0;
    

    into this for x86_64 (and x86):

        addl    $1, %esi  ; %esi=n
        cmpl    $1234, %esi
        cmove   %edx, %esi ; %edx contains 0
    

    (cmove is available since PentiumPro.)

    This comes out for ARM-thumb:

        add     r3, r3, #1
        cmp     r3, r1
        moveq   r3, #0 ; <- conditional move
    

    All ARMs have conditional execution.

    And so. To wrap it up: You’d need an architecture with

    • Very fast division/modulo
    • Expensive branch mispredictions
    • no conditional move

    to end up with the modulo trick as being the fastest. **If* there is such an architecture, then please tell me about it. I’m always interested in such things.

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

Sidebar

Ask A Question

Stats

  • Questions 536k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is what group_concat does. select group_concat(id) as video_list from… May 17, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer With optimizations enabled, they will compile identically. You should use… May 17, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer I finally figure this out. This happend when: try: raise… May 17, 2026 at 1:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using PuTTY to log into a Debian server. I have this odd problem
I am creating some RSS feeds using PHP (5.2) from a MySQL db specifically
Is there any disadvantage to using char for small integers in C? Are there
I initially assumed that since tcp has a sequence number field of 32 bits
Let's say we have a table \begin{tabular}{|c|c|} \begin{sideways}A\end{sideways}&\begin{sideways}B\end{sideways}\\\ a & b \\\ \end{tabular} How
I am using an embedded system running linux.I use a ramdisk filesystem on the
When you have a circular buffer represented as an array, and you need the
I want to calculate the average of a set of circular data. For example,
What kind of data structure could be used for an efficient nearest neighbor search
If a float overflow occurs on a value, I want to set it to

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.