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 113909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:46:36+00:00 2026-05-11T02:46:36+00:00

In my computer this code takes 17 seconds (1000 millions times): static void Main(string[]

  • 0

In my computer this code takes 17 seconds (1000 millions times):

static void Main(string[] args) {    var sw = new Stopwatch(); sw.Start();    int r;    for (int i = 1; i <= 100000000; i++) {       for (int j = 1; j <= 10; j++) {          MyDivRem (i,j, out r);       }    }    Console.WriteLine(sw.ElapsedMilliseconds); }  static int MyDivRem(int dividend, int divisor, out int remainder) {    int quotient = dividend / divisor;    remainder = dividend - divisor * quotient;    return quotient; } 

while Math.DivRem takes 27 seconds.

.NET Reflector gives me this code for Math.DivRem:

public static int DivRem(int a, int b, out int result) {     result = a % b;     return (a / b); } 

CIL

.method public hidebysig static int32 DivRem(int32 a, int32 b, [out] int32& result) cil managed {     .maxstack 8     L_0000: ldarg.2     L_0001: ldarg.0     L_0002: ldarg.1     L_0003: rem     L_0004: stind.i4     L_0005: ldarg.0     L_0006: ldarg.1     L_0007: div     L_0008: ret } 

Theoretically it may be faster for computers with multiple cores, but in fact it shouldn’t need to do two operations in the first place, because x86 CPUs return both the quotient and remainder when they do an integer division using DIV or IDIV (http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-2.html#HEADING2-451)!

  • 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-11T02:46:37+00:00Added an answer on May 11, 2026 at 2:46 am

    Grrr. The only reason for this function to exist is to take advantage of the CPU instruction for this, and they didn’t even do it!

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

Sidebar

Related Questions

So I have this code that takes care of command acknowledgment from remote computers,
I'm just finishing up a computer architecture course this semester where, among other things,
Ok this is more of a computer science question, than a question based on
This semester, I took a course in computer graphics at my University. At the
When I access my site from any computer, I see this warning popping up:
This is undeniable: multicore computers are here to stay. So is this: efficient multicore
After reading this on the question How do I uniquely identify computers visiting my
Arising out of this question, I'm looking for an elegant (ruby) way to compute
Computer Management -> Services and Applications -> Message Queues How to delete a message
I am observing a strange bug in some of my code which I suspect

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.