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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:12:49+00:00 2026-05-15T06:12:49+00:00

I have a result set that will never exceed 500; the results that come

  • 0

I have a result set that will never exceed 500; the results that come back from the web-service are assigned to a search results object.

The data from the webservice is about 2mb; the bit I want to use is about a third of each record, so this allows me to cache and quickly manipulate it.

I want to be able to sort and filter the results with the least amount of overhead and as fast as possible so I used the VCSKICKS timing class to measure their performance

              Average        Total (10,000)
Type       Create  Sort      Create  Sort
HashSet    0.1579  0.0003    1579    3
IList      0.0633  0.0002    633     2
IQueryable 0.0072  0.0432    72      432

Measured in Seconds using http://www.vcskicks.com/algorithm-performance.php

I created the hashset through a for loop over the web-service response (adding to the hashset).

The List & IQueryable were created using LINQ.

Question
I can understand why HashSet takes longer to create (the foreach loop vs linq); but why would IQueryable take longer to sort than the other two; and finally is there a better way to assign the HashSet.

Thanks

Actual Program

public class Program
{
    private static AuthenticationHeader _authHeader;
    private static OPSoapClient _opSession;
    private static AccommodationSearchResponse _searchResults;

    private static HashSet<SearchResults> _myHash;
    private static IList<SearchResults> _myList;
    private static IQueryable<SearchResults> _myIQuery;

    static void Main(string[] args)
    {
        #region Setup WebService
        _authHeader = new AuthenticationHeader { UserName = "xx", Password = "xx" };
        _opSession = new OPSoapClient();


        #region Setup Search Results

        _searchResults = _opgSession.SearchCR(_authHeader, "ENG", "GBP", "GBR");

        #endregion Setup Search Results

        #endregion Setup WebService


        // HASHSET
        SpeedTester hashTest = new SpeedTester(TestHashSet);
        hashTest.RunTest();
        Console.WriteLine("- Hash Test \nAverage Running Time: {0}; Total Time: {1}", 
            hashTest.AverageRunningTime, 
            hashTest.TotalRunningTime);

        SpeedTester hashSortTest = new SpeedTester(TestSortingHashSet);
        hashSortTest.RunTest();
        Console.WriteLine("- Hash Sort Test \nAverage Running Time: {0}; Total Time: {1}",
            hashSortTest.AverageRunningTime,
            hashSortTest.TotalRunningTime);

        // ILIST
        SpeedTester listTest = new SpeedTester(TestList);
        listTest.RunTest();
        Console.WriteLine("- List Test \nAverage Running Time: {0}; Total Time: {1}",
            listTest.AverageRunningTime,
            listTest.TotalRunningTime);

        SpeedTester listSortTest = new SpeedTester(TestSortingList);
        listSortTest.RunTest();
        Console.WriteLine("- List Sort Test \nAverage Running Time: {0}; Total Time: {1}",
            listSortTest.AverageRunningTime,
            listSortTest.TotalRunningTime);

        // IQUERIABLE
        SpeedTester iqueryTest = new SpeedTester(TestIQueriable);
        iqueryTest.RunTest();
        Console.WriteLine("- iquery Test \nAverage Running Time: {0}; Total Time: {1}",
            iqueryTest.AverageRunningTime,
            iqueryTest.TotalRunningTime);

        SpeedTester iquerySortTest = new SpeedTester(TestSortableIQueriable);
        iquerySortTest.RunTest();
        Console.WriteLine("- iquery Sort Test \nAverage Running Time: {0}; Total Time: {1}",
            iquerySortTest.AverageRunningTime,
            iquerySortTest.TotalRunningTime);
    }

    static void TestHashSet()
    {
        var test = _searchResults.Items;

        _myHash = new HashSet<SearchResults>();

        foreach(var x in test)
        {
            _myHash.Add(new SearchResults
                                     {
                                         Ref = x.Ref,
                                         Price = x.StandardPrice
                                     });
        }

    }

    static void TestSortingHashSet()
    {
        var sorted = _myHash.OrderBy(s => s.Price);
    }



    static void TestList()
    {
        var test = _searchResults.Items;

        _myList = (from x in test
                   select new SearchResults
                              {
                                  Ref = x.Ref,
                                  Price = x.StandardPrice
                              }).ToList();
    }

    static void TestSortingList()
    {
        var sorted = _myList.OrderBy(s => s.Price);
    }

    static void TestIQueriable()
    {
        var test = _searchResults.Items;

        _myIQuery = (from x in test
                     select new SearchResults
                                {
                                    Ref = x.Ref,
                                    Price = x.StandardPrice
                                }).AsQueryable();

    }

    static void TestSortableIQueriable()
    {
        var sorted = _myIQuery.OrderBy(s => s.Price);
    }

}

=== Direct Output from console ===

- Hash Test
Average Running Time: 0.154; Total Time: 1540
- Hash Sort Test
Average Running Time: 0.0003; Total Time: 3
- List Test
Average Running Time: 0.0601; Total Time: 601
- List Sort Test
Average Running Time: 0.0002; Total Time: 2
- iquery Test
Average Running Time: 0.0003; Total Time: 3
- iquery Sort Test
Average Running Time: 0.0399; Total Time: 399
- IEnum Test
Average Running Time: 0.0002; Total Time: 2
- IEnum Sort Test
Average Running Time: 0.0001; Total Time: 1
Press any key to continue . . .

Obviously times vary based on what my machine was doing at the time, you can usually make some judgement based on the size of the difference but as the ‘answer’ states its unfair to judge IQueryable the same way.

  • 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-15T06:12:51+00:00Added an answer on May 15, 2026 at 6:12 am

    I think IQueryable has deferred the creation until the sort was executed where the IList did the creation up front and then performed the sort on it.

    Just like the IList, the HashSet creation was not deferred and therefore the the big up front cost.

    So up front the HashSet and the IList have to be created which takes time which you record. Then you record the sorting on them which is probably negligible. The IQueryable deferred that creation time UNTIL you did the sort so the create and sort are all happening in the time for the sort. The sort didn’t really take longer for the IQueryable it just looks like it because the creation is happening at the same time in your testing. I would suspect that all 3 sort’s time differences are negligible.

    I think either way it is fine to use any of them depending on how you want the output to be used or extended in the case of IQueryable.

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

Sidebar

Related Questions

I have a SOAP result set that the nuSoap extension has turned into a
I have a query that creates a result set like this: Rank Name 1
I have a query that returns a result set similar to the one below:
I have a MYSQL stored procedure SP1() that returns a result set. I want
It seems that unless you call std::async a std::future will never be set to
I have a result of a db query in java.sql.ResultSet that needs to be
I have a java.sql.ResultSet object containg data from a query that was run. How
I have been facing issue with sphinx result set for string attribute. Below is
I have this query which returns a result set with Date(column) as nvarchar datatype.
So I have a function that looks like this: @SuppressWarnings(unchecked) public static <E> Set<E>

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.