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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:09:36+00:00 2026-05-20T20:09:36+00:00

Sorry for the vague thread title; hard to succinctly describe my question. I have

  • 0

Sorry for the vague thread title; hard to succinctly describe my question.

I have a collection of a large number of objects (couple thousand), defined as…

public class Item
{
    public int ID;
    public float A;
    public float B;
    public float C;
    public float D;
    public float E;
    public float F;
    public float G;
}

If I’m given a multiplier for each one of those float fields, what’s the fastest way to find which Item in my large collection has the largest total of those floats multiplied by their multiplier.

For example, I’ve currently got something like…

public Item FindLargest(float aMult, float bMult, float cMult, float dMult, float eMult, float fMult, float gMult)
{
    Item largest = null;
    float largestTotal = 0f;
    foreach(Item item in ItemsCollection)
    {
        float total = item.A * aMult + 
                      item.B * bMult + 
                      item.C * cMult + 
                      item.D * dMult + 
                      item.E * eMult + 
                      item.F * fMult + 
                      item.G * gMult;
        if (total > largestTotal)
        {
            largest = item;
            largestTotal = total;
        }
    }
    return largest;
}

The performance of this is lacking, and so I’m wondering if there’s anything I can do to restructure the data in such a way, ahead of time, so that the FindLargest call is much much faster. I’ve been doing it like this for a while, and performance was fine, with ~40-50 items in the ItemsCollection, but now the design of a different part of my application has changed, and as a byproduct, I need to process much larger set of data (~2000ish instead of ~50ish), so I’m interested in optimizing this further. Thanks for any help anyone can offer!

EDIT: I should have mentioned this to start with: I’m already parallelizing this in that what’s calling this is already heavily parallelized. And what’s calling this is indeed calling it many times, with many different parameters, very quickly. Every time a value changes in the open document in my app, this needs to be called about a hundred times, and it should feel ‘responsive’ (already doing all the calculations on multiple background threads, so I don’t mean UI lockup).

EDIT 2: See my comments in the accepted answer.

  • 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-20T20:09:36+00:00Added an answer on May 20, 2026 at 8:09 pm

    I don’t think the problem is with your function here. I’m taking way less than 0.1 seconds to complete the function with 500,000 items in the collection.

    You might want to find a way to optimize the part of the code that calls this function. Using PLINQ at that level should yield better results.

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

Sidebar

Related Questions

Sorry about the extremely vague question title (any suggestions for improvements welcome) I have
Sorry for vague question title. I've got a table containing huge list of, say,
Sorry for the vague title, as I really can't explain this problem succinctly. Basically
Sorry about the vague question title, I just want to ascertain some things. Static
Sorry about the vague title, but i didnt know how to ask the question
Sorry for the vague title, but this is kind of hard to put into
Sorry for the vague title. Here's an example of what I'd like to do.
Sorry about a vague title, but here's what i am trying to do. I
Sorry for the vague question.. but I'm not sure quite what the problem is.
Sorry for asking such a vague question, i'm new to using C# / ASP.NET.

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.