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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:56:51+00:00 2026-06-03T13:56:51+00:00

I have the following method that takes an extremely long time to run and

  • 0

I have the following method that takes an extremely long time to run and would love some help to make it run faster and or be more efficient.

The main responsibility of the method is to take a list of data points created from a CSV file, map the Name property of the file datapoints to the to the HistorianTagname property in a list of tagnames by the DataLoggerTagname property and create a resulting list from the mapping. If the mapping does not exist, the file datapoint is ignored.

I know it that was long-winded, but I hope it makes sense. It may be easier just to look at the method:

    private IEnumerable<DataPoint> GetHistorianDatapoints(IEnumerable<DataPoint> fileDatapoints, IEnumerable<Tagname> historianTagnames)
    {
        /**
         ** REFACTOR THIS 
         **/

        foreach (var fileDatapoint in fileDatapoints)
        {
            var historianTagname = historianTagnames.FirstOrDefault(x => x.DataLoggerTagname.Equals(fileDatapoint.Name, StringComparison.OrdinalIgnoreCase));
            if (historianTagname != null)
            {
                var historianDatapoint = new DataPoint();

                historianDatapoint.Name = historianTagname.HistorianTagname;
                historianDatapoint.Date = fileDatapoint.Date;
                historianDatapoint.Value = fileDatapoint.Value;

                yield return historianDatapoint;
            }
        }
    }

Notes:
I have complete control of classes and methods of mapping, so if I am doing something fundamentally wrong. I would love to know!

Thanks!

  • 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-03T13:56:52+00:00Added an answer on June 3, 2026 at 1:56 pm

    Below is my proposition:

    private IEnumerable<DataPoint> GetHistorianDatapoints(IEnumerable<DataPoint> fileDatapoints, IEnumerable<Tagname> historianTagnames)
    {
        var tagNameDictionary = historianTagnames.ToDictionary(t => t.DataLoggerTagname, StringComparer.OrdinalIgnoreCase);
    
        foreach (var fileDatapoint in fileDatapoints)
        {                
            if (tagNameDictionary.ContainsKey(fileDatapoint.Name))
            {
                var historianTagname = tagNameDictionary[fileDatapoint.Name];
                var historianDatapoint = new DataPoint();
    
                historianDatapoint.Name = historianTagname.HistorianTagname;
                historianDatapoint.Date = fileDatapoint.Date;
                historianDatapoint.Value = fileDatapoint.Value;
    
                yield return historianDatapoint;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following method that I would like to make shorter or faster if
I have the following method that takes in a details object, validates it, converts
I have the following extension method that takes a List and converts it to
I have a static class with a static constructor that takes some time (10-15
I have the following method that returns void and I need to use it
I have the following method that is replacing a pound sign from the file
I have the following method that is supposed to be a generic Save to
I have the following static method that prints the data imported from a 40.000
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a method that I will use in the following contexts: 1. User

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.