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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:29:06+00:00 2026-05-13T15:29:06+00:00

I need to resample big sets of data (few hundred spectra, each containing few

  • 0

I need to resample big sets of data (few hundred spectra, each containing few thousand points) using simple linear interpolation.

I have created interpolation method in C# but it seems to be really slow for huge datasets.

How can I improve the performance of this code?

public static List<double> interpolate(IList<double> xItems, IList<double> yItems, IList<double> breaks)
        {
                double[] interpolated = new double[breaks.Count];
                int id = 1;
                int x = 0;
                while(breaks[x] < xItems[0])
                {
                    interpolated[x] = yItems[0];
                    x++;
                }

                double p, w;
                // left border case - uphold the value
                for (int i = x; i < breaks.Count; i++) 
                {
                    while (breaks[i] > xItems[id])
                    {
                        id++;
                        if (id > xItems.Count - 1)
                        {
                            id = xItems.Count - 1;
                            break;
                        }
                    }

                    System.Diagnostics.Debug.WriteLine(string.Format("i: {0}, id {1}", i, id));

                    if (id <= xItems.Count - 1)
                    {
                        if (id == xItems.Count - 1 && breaks[i] > xItems[id])
                        {

                            interpolated[i] = yItems[yItems.Count - 1];
                        }
                        else
                        {
                            w = xItems[id] - xItems[id - 1];
                            p = (breaks[i] - xItems[id - 1]) / w;
                            interpolated[i] = yItems[id - 1] + p * (yItems[id] - yItems[id - 1]);
                        }
                    }
                    else // right border case - uphold the value
                    {
                        interpolated[i] = yItems[yItems.Count - 1];
                    }

                }
                return interpolated.ToList();

        }

Edit
Thanks, guys, for all your responses. What I wanted to achieve, when I wrote this questions, were some general ideas where I could find some areas to improve the performance. I haven’t expected any ready solutions, only some ideas. And you gave me what I wanted, thanks!

Before writing this question I thought about rewriting this code in C++ but after reading comments to Will’s asnwer it seems that the gain can be less than I expected.

Also, the code is so simple, that there are no mighty code-tricks to use here. Thanks to Petar for his attempt to optimize the code

It seems that all reduces the problem to finding good profiler and checking every line and soubroutine and trying to optimize that.

Thank you again for all responses and taking your part in this discussion!

  • 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-13T15:29:06+00:00Added an answer on May 13, 2026 at 3:29 pm

    I’d say profile the code and see where it spends its time, then you have somewhere to focus on.

    ANTS is popular, but Equatec is free I think.

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

Sidebar

Related Questions

need advice on data driven test automation. I am doing test automation using C#
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
I need to resize images and resample them so they don't end up all
Need advise I am currently using CRM4.0 webservice to create account from reading my
I'm using sox to resample audio before introducing it to our speech detection system,
Need help with implementing a pure abstract class via inheritance , using namespace to
Need to know if I need to worry about people using this on my
I'm developing an app that handle sets of financial series data (input as csv
Need to choose optimal data structure for fast work with list of locations and
Need to design a simple one for school. More specifically a Moore FSM. Im

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.