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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:19:30+00:00 2026-05-29T12:19:30+00:00

I am having the following code: public static IEnumerable<int> GetCloseZipCodes(int zipcode, int radius) {

  • 0

I am having the following code:

public static IEnumerable<int> GetCloseZipCodes(int zipcode, int radius)
        {
            PycDBDataContext db = new PycDBDataContext();

            ZipCode reqZipInfo = ZipCodes.Instance.zipcodes[zipcode];

            if (reqZipInfo == null)
                return new int[] { };

            double longt = LongitudePlusDistance((double)reqZipInfo.Longitude, (double)reqZipInfo.Latitude, radius);
            double latit = LatitudePlusDistance((double)reqZipInfo.Latitude, radius);
            double minLong = 2 * (double)reqZipInfo.Longitude - longt;
            double minLat = 2 * (double)reqZipInfo.Latitude - latit;

            var zips = ZipCodes.Instance.zipcodes.Where(x => (double)x.Value.Longitude >= minLong &&
                                                  (double)x.Value.Longitude <= longt &&
                                                  (double)x.Value.Latitude >= minLat &&
                                                  (double)x.Value.Latitude <= latit &&
                                                  CalcDistance((double)reqZipInfo.Longitude,
                                                  (double)reqZipInfo.Latitude, 
                                                  (double)x.Value.Longitude, 
                                                  (double)x.Value.Latitude) <= radius).Select(x => x.Key);

            return zips;
        }

This function is given with a zipcode, a radius and it will find all the zipcodes within the radius.
I have performance issues here and after running dotTrace most of my time is in the following:

var zips = ZipCodes.Instance.zipcodes.Where(x => (double)x.Value.Longitude >= minLong &&
                                                  (double)x.Value.Longitude <= longt &&
                                                  (double)x.Value.Latitude >= minLat &&
                                                  (double)x.Value.Latitude <= latit &&
                                                  CalcDistance((double)reqZipInfo.Longitude,
                                                  (double)reqZipInfo.Latitude, 
                                                  (double)x.Value.Longitude, 
                                                  (double)x.Value.Latitude) <= radius).Select(x => x.Key);

And third of the time there, it is accessing

public System.Nullable<decimal> Longitude
        {
            get
            {
                return this._Longitude;
            }
            set
            {
                if ((this._Longitude != value))
                {
                    this._Longitude = value;
                }
            }
        }

How can I improve the performance??? We are talking about a few seconds here…
I can’t understand why. this is all cached and non-SQL.

  • 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-29T12:19:30+00:00Added an answer on May 29, 2026 at 12:19 pm

    For one thing, you’re doing a lot of conversions between double and decimal as far as I can see.

    I’d suggest either changing your object representation to use double to start with, or convert longt and latit to decimal so that you can perform all the comparisons in a single type, without all the conversions.

    Aside from anything else, keeping one consistent representation will leave your code cleaner as well as probably performing better. In this case, I’d say that double is probably a more appropriate representation than decimal anyway – it’s not like these are exact decimal values like currency; they’re naturally-occurring values which have already been approximated by measurement.

    Additionally, you’re doing the nullable to non-nullable conversion several times, both for x.Value and for comparisons. Consider using a statement lambda instead:

    x => {
       if (x.Longitude == null || x.Latitude == null)
       {
           return false;
       }
       double longitude = x.Value.Longitude.Value;
       double latitude = x.Value.Latitude.Value;
       return longitude >= minLong &&
              longitude <= longt &&
              latitude >= minLat &&
              latitude <= latit &&
              longitude >= minLong &&
              CalcDistance(reqZipInfo.Longitude, reqZipInfo.Latitude,
                           longitude, latitude) <= radius;
    }
    

    For the sake of readability, I’d probably put this in a separate method to be honest.

    (Do you even need the properties to be nullable, by the way? It doesn’t make much sense to me.)

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

Sidebar

Related Questions

I am having following function public static Date parseDate(String date, String format) throws ParseException
consider the following two pieces of code: public static Time Parse(string value) { string
I am trying attempting to refactor the following code: public static void SaveSplitbar(RadSplitBar splitBar)
The following code does not compile: public class GenericsTest { public static void main(String[]
I have this following test code: public static final String[] list = { apple,ball,cat,dog,egg,fan,girl,hat,igloo,jerk
I have the following code: public static MyMethod() { ...Do something ProtectedMethod(param1, param2); ...Do
Assume I have the following code: public static class Foo { public static void
I m having the following code, however, I can see that the radio button
I am having following peice of code ,where in i am trying to serialize
Having sorted the tag_counts hash via the following code: sorted_tags = Contact.tag_counts.sort{ |x,y| x.name.downcase

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.