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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:33:32+00:00 2026-06-01T05:33:32+00:00

50\% of my simulation time is spent on the following code: internal double simWithdrawalFast(double

  • 0

50\% of my simulation time is spent on the following code:

    internal double simWithdrawalFast(double t)
    {
        simarrivals.Enqueue(t + Leadtime);
        return simarrivals.Dequeue();
    }

where simarrivals is a System.Collection.Generic.Queue<double>.

If I write my own queue, will it be faster?

EDIT: note that there are doubles in the queue to begin with, i.e. the queue has about 200 elements when simwithdrawal is called. Each call adds and removes an element.

  • 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-06-01T05:33:33+00:00Added an answer on June 1, 2026 at 5:33 am

    The implementations of these two methods seem pretty minimalist to me:

    public T Dequeue()
    {
      if (this._size == 0)
        ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EmptyQueue);
      T obj = this._array[this._head];
      this._array[this._head] = default (T);
      this._head = (this._head + 1) % this._array.Length;
      --this._size;
      ++this._version;
      return obj;
    }
    
    
    public void Enqueue(T item)
    {
      if (this._size == this._array.Length)
      {
        int capacity = (int) ((long) this._array.Length * 200L / 100L);
        if (capacity < this._array.Length + 4)
          capacity = this._array.Length + 4;
        this.SetCapacity(capacity);
      }
      this._array[this._tail] = item;
      this._tail = (this._tail + 1) % this._array.Length;
      ++this._size;
      ++this._version;
    }
    

    I have a hard time believing the semantics of a queue can be honored by code much more efficient than this. Therefore, your problem is probably at a higher level. Why is this method (simWithdrawalFast) getting called so much? You’re probably going to have to find a way to make your overall algorithm more efficient rather than finding a more efficient data structure.

    If the problem is frequent resizing of the queue, you might be able to improve the performance somewhat by specifying a capacity when constructing the queue. My hunch though is that this isn’t your problem.

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

Sidebar

Related Questions

The situation is that I've spent some time messing around with some experimental code.
I've spent a long time building stochastic simulations in Java. They work great, but
I recently spent some time chasing an annoying little bug and I'm looking for
I spent a very long time trying to locate the error but I can't
I've spent lots of time searching a solution to this, tried Google it, BING
I've spent quite a lot of time today trying various things, but none of
I am fairly new to WPF but have spent time researching WPF validation, and
We have a situation in our product where for a long time some data
I have a situation where I have a product and a time dimension, with
I'm struggling with a situation that I come up again time and time again

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.