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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:41:23+00:00 2026-05-12T19:41:23+00:00

We need to represent huge numbers in our application. We’re doing this using integer

  • 0

We need to represent huge numbers in our application. We’re doing this using integer arrays. The final production should be maxed for performance. We were thinking about encapsulating our array in a class so we could add properties to be related to the array such as isNegative, numberBase and alike.

We’re afraid that using classes, however, will kill us performance wise. We did a test where we created a fixed amount of arrays and set it’s value through pure arrays usage and where a class was created and the array accessed through the class:

for (int i = 0; i < 10000; i++)
{
    if (createClass)
    {
        BigNumber b = new BigNumber(new int[5000], 10);
        for (int j = 0; j < b.Number.Length; j++)
        {
            b[j] = 5;
        }
    }
    else
    {
        int[] test = new int[5000];
        for (int j = 0; j < test.Length; j++)
        {
            test[j] = 5;
        }
    }
}

And it appears that using classes slows down the runnign time of the above code by a factor 6 almost. We tried the above just by encapsulating the array in a struct instead which caused the running time to be almost equal to pure array usage.

What is causing this huge overhead when using classes compared to structs? Is it really just the performance gain you get when you use the stack instead of the heap?

BigNumber just stores the array in a private variable exposed by a property. Simplified:

public class BigNumber{
  private int[] number;

  public BigNumber(int[] number) { this.number = number;}

  public int[] Number{get{return number;}}
}
  • 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-12T19:41:23+00:00Added an answer on May 12, 2026 at 7:41 pm

    It’s not surprising that the second loop is much faster than the first one. What’s happening is not that the class is extraordinarily slow, it’s that the loop is really easy for the compiler to optimize.

    As the loop ranges from 0 to test.Length-1, the compiler can tell that the index variable can never be outside of the array, so it can remove the range check when accessing the array by index.

    In the first loop the compiler can’t do the connection between the loop and the array, so it has to check the index against the boundaries for each item that is accessed.

    There will always be a bit of overhead when you encapsulate an array inside a class, but it’s not as much as the difference that you get in your test. You have chosen a situation where the compiler is able to optimize the plain array access very well, so what you are testing is more the compilers capability to optimize the code rather than what you set out to test.

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

Sidebar

Ask A Question

Stats

  • Questions 222k
  • Answers 222k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Basically you need to edit the grammar file to add… May 13, 2026 at 12:18 am
  • Editorial Team
    Editorial Team added an answer This is not the question you should be asking IMO.… May 13, 2026 at 12:18 am
  • Editorial Team
    Editorial Team added an answer Are you using TreeView.GotFocus when you really want TreeViewItem.Selected? <TreeView… May 13, 2026 at 12:18 am

Related Questions

We need to represent huge numbers in our application. We're doing this using integer
When I convert an unsigned 8-bit int to string then I know the result
We generate graphs for huge datasets. We are talking 4096 samples per second, and
We need to call an executable from ant that takes xml as part of
Delphi 2009 has changed its string type to use 2 bytes to represent a

Trending Tags

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

Top Members

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.